Skip to content

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

chore: files changed crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout

Steven Enamakel55be87f8b7c0
diff --git a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs
index c482568561..db8bc3ebf9 100644
--- a/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs
+++ b/crates/openhuman-core/src/agent/orchestration/tools/agent_prepare_context/scout_run.rs
@@ -168,14 +168,14 @@ pub(super) fn scout_failure_signal(err: &SubagentRunError) -> String {
/// Two billing shapes reach here, both **user-state, not defects**:
/// * the managed OpenHuman backend's budget-exhausted 400
/// (`{"error":"Insufficient budget","errorCode":"USER_INSUFFICIENT_CREDITS"}`),
-/// matched by [`crate::api::classify::is_budget_exhausted_message`];
+/// matched by [`crate::backend::classify::is_budget_exhausted_message`];
/// * a BYO provider's insufficient-credits 402, matched by
/// [`crate::core::observability::is_insufficient_credits_message`].
///
/// Both delegate to the crate's single-source classifiers so the phrase sets
/// can't drift from the cron halt / `before_send` nets that share them.
pub(super) fn is_expected_billing_failure(message: &str) -> bool {
- crate::api::classify::is_budget_exhausted_message(message)
+ crate::backend::classify::is_budget_exhausted_message(message)
|| crate::core::observability::is_insufficient_credits_message(message)
}
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse/environment.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse/environment.rs
index 0c07b4adc4..9179f7f886 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse/environment.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse/environment.rs
@@ -17,12 +17,12 @@ const INGESTION_PATH: &str = "/telemetry/langfuse/ingestion";
/// Resolve the Langfuse ingestion URL from the current backend host. Joins the
/// proxy path onto [`effective_backend_api_url`] — the exact base-server
/// resolution every other backend call uses — via the canonical
-/// [`crate::api::config::api_url`] helper, which replaces any path the base
+/// [`crate::util::url::join_url`] helper, which replaces any path the base
/// carried with the given absolute path. So the host always matches wherever the
/// app's domain calls go (staging, prod, or a custom `api_url` override).
pub(crate) fn ingestion_url(config: &Config) -> String {
let base = effective_backend_api_url(&config.api_url);
- crate::api::config::api_url(&base, INGESTION_PATH)
+ crate::util::url::join_url(&base, INGESTION_PATH)
}
/// The domain the deployed backends live under. A host outside it cannot be
@@ -54,7 +54,7 @@ const DEPLOYMENT_DOMAIN: &str = "tinyhumans.ai";
/// classified as external, so a working development setup would have
/// silently stopped exporting the moment the gate landed.
///
-/// Host classification is delegated to [`crate::api::config::host_is_local`],
+/// Host classification is delegated to [`crate::util::url::host_is_local`],
/// which already parses the URL and handles IPv4 loopback/unspecified/private,
/// IPv6 loopback/unspecified, and `localhost` / `*.localhost`. Keeping one
/// definition matters more than the few lines it saves: two local-host
@@ -69,7 +69,7 @@ pub(crate) fn environment_for_base(base: &str) -> &'static str {
let Ok(parsed) = url::Url::parse(base) else {
return "external";
};
- if crate::api::config::host_is_local(&parsed) {
+ if crate::util::url::host_is_local(&parsed) {
return "development";
}
if parsed.scheme() != "https" {
diff --git a/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs b/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs
index 3c907f1866..a0c8f4e279 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/langfuse/span_export.rs
@@ -4,7 +4,7 @@
use serde_json::{json, Map, Value};
-use crate::api::jwt::bearer_authorization_value;
+use crate::security::credentials::jwt::bearer_authorization_value;
use crate::config::Config;
use crate::security::credentials::session_support::direct_backend_credential;
@@ -278,7 +278,7 @@ pub(crate) async fn push_spans(config: &Config, spans: &[TraceSpan]) -> Result<(
// `ingestion_url` resolves to the backend's own Langfuse proxy route on the
// backend host, authenticated with a TinyHumans session token — backend
// traffic, so it carries the product identity. This is a bare
- // `reqwest::Client`, not `BackendOAuthClient`'s, so nothing is inherited
+ // `reqwest::Client`, not `BackendClient`'s, so nothing is inherited
// from that path's default headers; see [`crate::api::product`].
let (product_header, product_value) = crate::api::product::product_identity_header();
let response = reqwest::Client::new()
diff --git a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
index a3d36f6c63..49c90b613c 100644
--- a/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
+++ b/crates/openhuman-core/src/agent/progress_tracing/otlp.rs
@@ -7,7 +7,7 @@ use sha2::{Digest, Sha256};
use super::langfuse::{environment_for_base, ingestion_url, skip_push};
use super::types::{SpanKind, SpanStatus, TraceSpan};
-use crate::api::jwt::bearer_authorization_value;
+use crate::security::credentials::jwt::bearer_authorization_value;
use crate::config::Config;
use crate::security::credentials::session_support::direct_backend_credential;
diff --git a/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs b/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
index 501a50a0f5..d6e0ad219b 100644
--- a/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
+++ b/crates/openhuman-core/src/agent/tinyagents/middleware/loop_guards.rs
@@ -113,7 +113,7 @@ fn has_inference_failure_envelope(result: &str) -> bool {
/// the two tight provider classifiers. Budget takes precedence if both match.
/// Ported from legacy `tool_loop::terminal_inference_failure_kind` (#3104).
pub(crate) fn terminal_inference_failure_kind(result: &str) -> Option<TerminalInferenceFailure> {
- use crate::api::classify::is_budget_exhausted_message;
+ use crate::backend::classify::is_budget_exhausted_message;
use tinyinference_providers::is_provider_config_rejection_message;
if !has_inference_failure_envelope(result) {
return None;
diff --git a/crates/openhuman-core/src/backend/client.rs b/crates/openhuman-core/src/backend/client.rs
index 6e0da867a8..91514319f3 100644
--- a/crates/openhuman-core/src/backend/client.rs
+++ b/crates/openhuman-core/src/backend/client.rs
@@ -7,7 +7,7 @@ use reqwest::{Client, Method, Url};
use serde_json::{json, Value};
use std::sync::Arc;
-use crate::api::transport::{
+use crate::backend::transport::{
resolve_backend_transport, BackendRequest, BackendTransport, BackendTransportError,
TransportProfile,
};
@@ -333,17 +333,17 @@ pub fn user_id_from_profile_payload(payload: &Value) -> Option<String> {
/// A client for interacting with the TinyHumans / AlphaHuman backend API.
///
/// Owns the *routes* and the error classification; the HTTP round-trip itself
-/// rides the process [`BackendTransport`] (see [`crate::api::transport`]),
+/// rides the process [`BackendTransport`] (see [`crate::backend::transport`]),
/// which is what carries TLS, timeouts, attribution headers and the
/// credential header shape. A core with no transport installed answers every
/// call with [`BackendApiError::BackendUnavailable`].
#[derive(Clone)]
-pub struct BackendOAuthClient {
+pub struct BackendClient {
base: Url,
}
-impl BackendOAuthClient {
- /// Creates a new `BackendOAuthClient` with the given API base URL.
+impl BackendClient {
+ /// Creates a new `BackendClient` with the given API base URL.
///
/// Any path, query, or fragment in `api_base` is stripped so that
/// `Url::join` always resolves root-relative REST paths correctly.
@@ -664,7 +664,7 @@ impl BackendOAuthClient {
let is_transient_infra =
crate::core::observability::is_transient_http_status_code(status_code);
let is_budget_exhausted =
- status_code == 400 && crate::api::classify::is_budget_exhausted_message(&text);
+ status_code == 400 && crate::backend::classify::is_budget_exhausted_message(&text);
if is_budget_exhausted {
tracing::info!(
method = method.as_str(),
diff --git a/crates/openhuman-core/src/backend/client_tests.rs b/crates/openhuman-core/src/backend/client_tests.rs
index 6199daadbf..374e8afc4c 100644
--- a/crates/openhuman-core/src/backend/client_tests.rs
+++ b/crates/openhuman-core/src/backend/client_tests.rs
@@ -1,6 +1,6 @@
use super::{
backend_api_body_shape, flatten_authed_error, is_unmatched_route_404, key_bytes_from_string,
- parse_message_path, BackendApiError, BackendOAuthClient, BACKEND_API_BODY_SHAPE_MAX_BYTES,
+ parse_message_path, BackendApiError, BackendClient, BACKEND_API_BODY_SHAPE_MAX_BYTES,
};
use crate::api::headers::sanitize_client_version;
use crate::api::product::{
@@ -204,7 +204,7 @@ async fn spawn_header_capture_server() -> (String, CapturedHeaders) {
#[tokio::test]
async fn backend_client_sends_x_core_version_on_auth_requests() {
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let profile = client
.authed_json("test-jwt", Method::GET, "auth/me", None)
@@ -236,7 +236,7 @@ async fn authed_json_sends_an_api_key_as_x_api_key_and_no_bearer() {
use crate::security::credentials::session_support::BackendCredential;
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let response = client
.authed_json(
@@ -269,7 +269,7 @@ async fn authed_json_sends_a_session_credential_as_a_bearer_only() {
use crate::security::credentials::session_support::BackendCredential;
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
client
.authed_json(
@@ -295,7 +295,7 @@ async fn authed_json_sends_a_session_credential_as_a_bearer_only() {
#[tokio::test]
async fn authed_json_sends_bearer_and_host_headers() {
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let response = client
.authed_json("sdk-cutover-token", Method::GET, "/probe", None)
@@ -326,7 +326,7 @@ async fn backend_client_sends_x_tauri_version_when_env_set() {
std::env::set_var("OPENHUMAN_TAURI_VERSION", "9.8.7-shell+test");
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let url = client.url_for("/probe").unwrap();
let response = client.raw_client().unwrap().get(url).send().await.unwrap();
assert!(response.status().is_success());
@@ -346,17 +346,17 @@ async fn backend_client_sends_x_tauri_version_when_env_set() {
// Regression: OPENHUMAN-TAURI-8K / Sentry issue 7473650958.
// When config.api_url is a full LLM completions URL (e.g. /v1/chat/completions),
// Url::join used to produce wrong paths like /v1/chat/teams/me/usage instead of
-// /teams/me/usage — BackendOAuthClient::new must strip the path to prevent this.
+// /teams/me/usage — BackendClient::new must strip the path to prevent this.
#[test]
fn new_strips_path_from_completions_url() {
- let client = BackendOAuthClient::new("https://api.tinyhumans.ai/v1/chat/completions").unwrap();
+ let client = BackendClient::new("https://api.tinyhumans.ai/v1/chat/completions").unwrap();
let url = client.url_for("/teams/me/usage").unwrap();
assert_eq!(url.path(), "/teams/me/usage");
}
#[test]
fn new_strips_path_from_openai_style_url() {
- let client = BackendOAuthClient::new("https://api.openai.com/v1/chat/completions").unwrap();
+ let client = BackendClient::new("https://api.openai.com/v1/chat/completions").unwrap();
let url = client.url_for("/teams/me/usage").unwrap();
assert_eq!(url.path(), "/teams/me/usage");
assert_eq!(url.host_str(), Some("api.openai.com"));
@@ -364,14 +364,14 @@ fn new_strips_path_from_openai_style_url() {
#[test]
fn new_works_with_bare_origin() {
- let client = BackendOAuthClient::new("https://api.tinyhumans.ai").unwrap();
+ let client = BackendClient::new("https://api.tinyhumans.ai").unwrap();
let url = client.url_for("/teams/me/usage").unwrap();
assert_eq!(url.path(), "/teams/me/usage");
}
#[test]
fn new_works_with_trailing_slash() {
- let client = BackendOAuthClient::new("https://api.tinyhumans.ai/").unwrap();
+ let client = BackendClient::new("https://api.tinyhumans.ai/").unwrap();
let url = client.url_for("/teams/me/usage").unwrap();
assert_eq!(url.path(), "/teams/me/usage");
}
@@ -379,7 +379,7 @@ fn new_works_with_trailing_slash() {
#[tokio::test]
async fn backend_raw_client_inherits_x_core_version_default_header() {
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let url = client.url_for("/probe").unwrap();
let response = client.raw_client().unwrap().get(url).send().await.unwrap();
@@ -403,7 +403,7 @@ async fn sdk_path_sends_the_default_product_identity() {
reset_product_identity_for_test();
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
client
.authed_json("session-token", Method::GET, "/probe", None)
@@ -429,7 +429,7 @@ async fn raw_client_sends_the_product_identity_alongside_the_version_headers() {
reset_product_identity_for_test();
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let url = client.url_for("/probe").unwrap();
let response = client.raw_client().unwrap().get(url).send().await.unwrap();
@@ -456,7 +456,7 @@ async fn an_embedding_product_can_override_the_product_identity() {
set_product_identity(ProductIdentity::new("opencompany").unwrap());
let (base_url, captured) = spawn_header_capture_server().await;
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let sdk_result = client
.authed_json("session-token", Method::GET, "/probe", None)
@@ -504,7 +504,7 @@ async fn authed_json_surfaces_message_not_found_on_404() {
});
let base_url = format!("http://{addr}");
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
// Telegram path — matches OPENHUMAN-TAURI-2Y shape.
let err = client
@@ -573,7 +573,7 @@ async fn authed_json_surfaces_unauthorized_on_401() {
});
let base_url = format!("http://{addr}");
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
// Mascot TTS path — the original reporter.
let err = client
@@ -628,7 +628,7 @@ async fn authed_json_surfaces_api_key_rejected_not_unauthorized_on_401() {
});
let base_url = format!("http://{addr}");
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let err = client
.authed_json(
@@ -766,7 +766,7 @@ async fn authed_json_reports_non_channel_404_still_propagates() {
});
let base_url = format!("http://{addr}");
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let err = client
.authed_json("mock-jwt", Method::GET, "/teams/me/usage", None)
@@ -860,7 +860,7 @@ async fn authed_json_403_is_not_demoted_to_unauthorized() {
});
let base_url = format!("http://{addr}");
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let err = client
.authed_json("mock-jwt", Method::POST, "/openai/v1/audio/speech", None)
@@ -888,7 +888,7 @@ async fn authed_json_404_outside_messages_path_still_reports() {
});
let base_url = format!("http://{addr}");
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let err = client
.authed_json("mock-jwt", Method::GET, "/auth/profile", None)
@@ -969,7 +969,7 @@ async fn authed_json_patch_404_with_base_path_prefix_does_not_report() {
// Regression for TAURI-R7: if the resolved URL has a base-path prefix,
// authed_json must still suppress the 404 — NOT call report_error.
//
- // Since BackendOAuthClient strips the base path in `new()`, the path
+ // Since BackendClient strips the base path in `new()`, the path
// passed to authed_json is always joined against the stripped base. We
// verify that a PATCH 404 returns an error without panicking and that it
// is not classified as a code bug (no Sentry event).
@@ -990,7 +990,7 @@ async fn authed_json_patch_404_with_base_path_prefix_does_not_report() {
});
let base_url = format!("http://{addr}");
- let client = BackendOAuthClient::new(&base_url).unwrap();
+ let client = BackendClient::new(&base_url).unwrap();
let err = client
.authed_json(
@@ -1038,7 +1038,7 @@ async fn send_channel_edit_404_is_route_absence_not_a_missing_message() {
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
.send_channel_edit("telegram", "1103", "mock-jwt", serde_json::json!({}))
.await
@@ -1082,7 +1082,7 @@ async fn channel_edit_404_from_a_real_handler_stays_a_missing_message() {
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
.send_channel_edit("telegram", "1103", "mock-jwt", serde_json::json!({}))
.await
@@ -1118,7 +1118,7 @@ async fn channel_edit_404_on_a_prefixed_path_keeps_the_parsed_ids() {
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
.authed_json(
"mock-jwt",
@@ -1162,7 +1162,7 @@ async fn channel_edit_404_on_an_undecomposable_path_falls_back_to_unknown_ids()
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
.authed_json(
"mock-jwt",
@@ -1203,7 +1203,7 @@ async fn channel_delete_404_still_means_the_message_is_gone() {
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
.send_channel_delete("telegram", "1103", "mock-jwt")
.await
@@ -1234,7 +1234,7 @@ async fn sdk_backed_channel_delete_surfaces_message_not_found_on_404() {
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
.send_channel_delete("telegram", "1103", "mock-jwt")
.await
@@ -1264,7 +1264,7 @@ async fn sdk_backed_channel_typing_surfaces_unauthorized_on_401() {
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
let err = client
.send_channel_typing("telegram", "mock-jwt")
.await
@@ -1306,7 +1306,7 @@ async fn sdk_backed_calls_send_the_core_version_header() {
axum::serve(listener, app).await.unwrap();
});
- let client = BackendOAuthClient::new(&format!("http://{addr}")).unwrap();
+ let client = BackendClient::new(&format!("http://{addr}")).unwrap();
client
.send_channel_typing("telegram", "mock-jwt")
.await
diff --git a/crates/openhuman-core/src/channels/bus/delivery.rs b/crates/openhuman-core/src/channels/bus/delivery.rs
index cf0c47434e..51a0bb1118 100644
--- a/crates/openhuman-core/src/channels/bus/delivery.rs
+++ b/crates/openhuman-core/src/channels/bus/delivery.rs
@@ -27,8 +27,8 @@ pub(super) async fn delete_channel_message(channel: &str, message_id: &str) {
);
}
Err(err) => {
- if let Some(crate::api::rest::BackendApiError::MessageNotFound { .. }) =
- err.downcast_ref::<crate::api::rest::BackendApiError>()
+ if let Some(crate::backend::BackendApiError::MessageNotFound { .. }) =
+ err.downcast_ref::<crate::backend::BackendApiError>()
{
tracing::info!(
"[channel-inbound] delete channel='{}' msg_id={} — message already gone provider-side (404), nothing to clean up",
@@ -208,7 +208,7 @@ fn relay_session_token(config: &crate::config::Config, op: &str) -> Option<Strin
/// Construct the REST client + 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::backend::BackendClient, String)>
{
let config = match crate::config::rpc::load_config_with_timeout().await {
Ok(c) => c,
@@ -219,7 +219,7 @@ 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 = relay_session_token(&config, "send")?;
- match crate::api::rest::BackendOAuthClient::new(&api_url) {
+ match crate::backend::BackendClient::new(&api_url) {
Ok(c) => Some((c, jwt)),
Err(e) => {
tracing::error!("[channel-inbound] failed to create API client: {}", e);
@@ -243,7 +243,7 @@ pub(super) async fn send_channel_reply(channel: &str, text: &str) {
return;
};
- let client = match crate::api::rest::BackendOAuthClient::new(&api_url) {
+ let client = match crate::backend::BackendClient::new(&api_url) {
Ok(c) => c,
Err(e) => {
tracing::error!("[channel-inbound] failed to create API client: {}", e);
diff --git a/crates/openhuman-core/src/channels/bus/progressive_ui.rs b/crates/openhuman-core/src/channels/bus/progressive_ui.rs
index 51a0a82476..694f73a960 100644
--- a/crates/openhuman-core/src/channels/bus/progressive_ui.rs
+++ b/crates/openhuman-core/src/channels/bus/progressive_ui.rs
@@ -94,11 +94,11 @@ pub(super) enum EditFailure {
/// Classify an edit failure by typed error rather than by message text, so the
/// recovery a call site picks cannot drift with `#[error(...)]` wording.
pub(super) fn classify_edit_failure(err: &anyhow::Error) -> EditFailure {
- match err.downcast_ref::<crate::api::rest::BackendApiError>() {
- Some(crate::api::rest::BackendApiError::ChannelEditUnsupported { .. }) => {
+ match err.downcast_ref::<crate::backend::BackendApiError>() {
+ Some(crate::backend::BackendApiError::ChannelEditUnsupported { .. }) => {
EditFailure::RouteUnsupported
}
- Some(crate::api::rest::BackendApiError::MessageNotFound { .. }) => EditFailure::MessageGone,
+ Some(crate::backend::BackendApiError::MessageNotFound { .. }) => EditFailure::MessageGone,
_ => EditFailure::Transient,
}
}
diff --git a/crates/openhuman-core/src/channels/bus_tests.rs b/crates/openhuman-core/src/channels/bus_tests.rs
index e0cc9e5f51..bcaaa8af62 100644
--- a/crates/openhuman-core/src/channels/bus_tests.rs
+++ b/crates/openhuman-core/src/channels/bus_tests.rs
@@ -1,5 +1,5 @@
use super::*;
-use crate::api::rest::BackendApiError;
+use crate::backend::BackendApiError;
use crate::core::events::DomainEvent;
use tinybus::EventHandler;
diff --git a/crates/openhuman-core/src/channels/controllers/ops/messaging.rs b/crates/openhuman-core/src/channels/controllers/ops/messaging.rs
index ef743a6efb..7b10ae51ca 100644
--- a/crates/openhuman-core/src/channels/controllers/ops/messaging.rs
+++ b/crates/openhuman-core/src/channels/controllers/ops/messaging.rs
@@ -3,8 +3,8 @@
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::security::credentials::jwt::get_session_token;
+use crate::backend::BackendClient;
use crate::config::Config;
use crate::rpc::RpcOutcome;
@@ -24,14 +24,14 @@ pub async fn channel_send_message(
api_url
);
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
let result = client
.send_channel_message(channel, &jwt, message)
.await
.map_err(|e| {
format!(
"failed to send channel message: {}",
- crate::api::flatten_authed_error(e)
+ crate::backend::flatten_authed_error(e)
)
})?;
@@ -56,14 +56,14 @@ pub async fn channel_send_reaction(
api_url
);
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
let result = client
.send_channel_reaction(channel, &jwt, reaction)
.await
.map_err(|e| {
format!(
"failed to send channel reaction: {}",
- crate::api::flatten_authed_error(e)
+ crate::backend::flatten_authed_error(e)
)
})?;
@@ -89,14 +89,14 @@ pub async fn channel_create_thread(
api_url
);
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
let result = client
.create_channel_thread(channel, &jwt, title)
.await
.map_err(|e| {
format!(
"failed to create channel thread: {}",
- crate::api::flatten_authed_error(e)
+ crate::backend::flatten_authed_error(e)
)
})?;
@@ -124,14 +124,14 @@ pub async fn channel_update_thread(
api_url
);
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
let result = client
.update_channel_thread(channel, &jwt, thread_id, action)
.await
.map_err(|e| {
format!(
"failed to update channel thread: {}",
- crate::api::flatten_authed_error(e)
+ crate::backend::flatten_authed_error(e)
)
})?;
@@ -157,14 +157,14 @@ pub async fn channel_list_threads(
api_url
);
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
let result = client
.list_channel_threads(channel, &jwt, active)
.await
.map_err(|e| {
format!(
"failed to list channel threads: {}",
- crate::api::flatten_authed_error(e)
+ crate::backend::flatten_authed_error(e)
)
})?;
diff --git a/crates/openhuman-core/src/config/ops/loader/paths.rs b/crates/openhuman-core/src/config/ops/loader/paths.rs
index c758907c27..3ac50bb8d8 100644
--- a/crates/openhuman-core/src/config/ops/loader/paths.rs
+++ b/crates/openhuman-core/src/config/ops/loader/paths.rs
@@ -17,8 +17,8 @@ pub(crate) fn default_openhuman_dir() -> PathBuf {
}
pub(crate) fn env_scoped_fallback_root_dir() -> PathBuf {
- let suffix = if crate::api::config::is_staging_app_env(
- crate::api::config::app_env_from_env().as_deref(),
+ let suffix = if crate::config::app_env::is_staging_app_env(
+ crate::config::app_env::app_env_from_env().as_deref(),
) {
"-staging"
} else {
diff --git a/crates/openhuman-core/src/config/schema/load/dirs.rs b/crates/openhuman-core/src/config/schema/load/dirs.rs
index 8d811f1929..d981c5969b 100644
--- a/crates/openhuman-core/src/config/schema/load/dirs.rs
+++ b/crates/openhuman-core/src/config/schema/load/dirs.rs
@@ -39,7 +39,7 @@ pub const ACTION_DIR_ENV_VAR: &str = "OPENHUMAN_ACTION_DIR";
pub const MEMORY_SYNC_INTERVAL_SECS_ENV_VAR: &str = "OPENHUMAN_MEMORY_SYNC_INTERVAL_SECS";
fn default_root_dir_name() -> &'static str {
- if crate::api::config::is_staging_app_env(crate::api::config::app_env_from_env().as_deref()) {
+ if crate::config::app_env::is_staging_app_env(crate::config::app_env::app_env_from_env().as_deref()) {
".openhuman-staging"
} else {
".openhuman"
diff --git a/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs b/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs
index acf06239b5..590b579b9c 100644
--- a/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs
+++ b/crates/openhuman-core/src/config/schema/load_active_user_and_dirs_tests.rs
@@ -148,18 +148,18 @@ fn default_root_dir_name_uses_staging_suffix_for_staging_env() {
let _env_guard = crate::config::TEST_ENV_LOCK
.lock()
.unwrap_or_else(|e| e.into_inner());
- let prior = std::env::var(crate::api::config::APP_ENV_VAR).ok();
+ let prior = std::env::var(crate::config::app_env::APP_ENV_VAR).ok();
- std::env::set_var(crate::api::config::APP_ENV_VAR, "staging");
- assert!(crate::api::config::is_staging_app_env(Some("staging")));
+ std::env::set_var(crate::config::app_env::APP_ENV_VAR, "staging");
+ assert!(crate::config::app_env::is_staging_app_env(Some("staging")));
assert_eq!(default_root_dir_name(), ".openhuman-staging");
- std::env::set_var(crate::api::config::APP_ENV_VAR, "production");
+ std::env::set_var(crate::config::app_env::APP_ENV_VAR, "production");
assert_eq!(default_root_dir_name(), ".openhuman");
match prior {
- Some(value) => std::env::set_var(crate::api::config::APP_ENV_VAR, value),
- None => std::env::remove_var(crate::api::config::APP_ENV_VAR),
+ Some(value) => std::env::set_var(crate::config::app_env::APP_ENV_VAR, value),
+ None => std::env::remove_var(crate::config::app_env::APP_ENV_VAR),
}
}
diff --git a/crates/openhuman-core/src/config/schema/types/defaults.rs b/crates/openhuman-core/src/config/schema/types/defaults.rs
index 649a8bda0a..ad9fc86110 100644
--- a/crates/openhuman-core/src/config/schema/types/defaults.rs
+++ b/crates/openhuman-core/src/config/schema/types/defaults.rs
@@ -14,8 +14,8 @@ impl Default for Config {
let openhuman_dir = crate::config::default_root_openhuman_dir().unwrap_or_else(|_| {
let home =
UserDirs::new().map_or_else(|| PathBuf::from("."), |u| u.home_dir().to_path_buf());
- let dir_name = if crate::api::config::is_staging_app_env(
- crate::api::config::app_env_from_env().as_deref(),
+ let dir_name = if crate::config::app_env::is_staging_app_env(
+ crate::config::app_env::app_env_from_env().as_deref(),
) {
".openhuman-staging"
} else {
diff --git a/crates/openhuman-core/src/core/cli_tests.rs b/crates/openhuman-core/src/core/cli_tests.rs
index fc3841c105..31a3839719 100644
--- a/crates/openhuman-core/src/core/cli_tests.rs
+++ b/crates/openhuman-core/src/core/cli_tests.rs
@@ -56,7 +56,7 @@ fn launch_options_reject_missing_or_empty_values() {
/// these tests set `BACKEND_URL`, which `api::config`
/// tests also read/remove, so a module-local lock is not enough.
fn env_lock() -> std::sync::MutexGuard<'static, ()> {
- crate::api::config::backend_env_test_lock()
+ crate::config::app_env::env_test_lock()
}
#[test]
diff --git a/crates/openhuman-core/src/core/jsonrpc.rs b/crates/openhuman-core/src/core/jsonrpc.rs
index 05d1b0684d..03c751071c 100644
--- a/crates/openhuman-core/src/core/jsonrpc.rs
+++ b/crates/openhuman-core/src/core/jsonrpc.rs
@@ -1729,7 +1729,7 @@ fn register_domain_subscribers(
log::info!("[auth] api-key credential present at startup — scheduler gate signed in");
crate::cron::scheduler_gate::set_signed_out(false);
} else {
- match crate::api::jwt::get_session_token(&config) {
+ match crate::security::credentials::jwt::get_session_token(&config) {
Ok(Some(_)) => {
crate::cron::scheduler_gate::set_signed_out(false);
}
diff --git a/crates/openhuman-core/src/core/jsonrpc_tests.rs b/crates/openhuman-core/src/core/jsonrpc_tests.rs
index bcf13f25cb..469e4b5a43 100644
--- a/crates/openhuman-core/src/core/jsonrpc_tests.rs
+++ b/crates/openhuman-core/src/core/jsonrpc_tests.rs
@@ -673,8 +673,8 @@ fn is_session_expired_error_matches_flattened_backend_unauthorized() {
// 401 is suppressed from Sentry (TAURI-RUST-8WY on `/teams/me/usage`,
// TAURI-RUST-8WZ on `/payments/stripe/currentPlan`) AND triggers the
// `SessionExpired` publish. End-to-end: build the typed error → flatten → classify.
- let flat = crate::api::flatten_authed_error(anyhow::Error::new(
- crate::api::BackendApiError::Unauthorized {
+ let flat = crate::backend::flatten_authed_error(anyhow::Error::new(
+ crate::backend::BackendApiError::Unauthorized {
method: "GET".to_string(),
path: "/teams/me/usage".to_string(),
},
diff --git a/crates/openhuman-core/src/core/observability.rs b/crates/openhuman-core/src/core/observability.rs
index b27e7e150a..8b4f5020c0 100644
--- a/crates/openhuman-core/src/core/observability.rs
+++ b/crates/openhuman-core/src/core/observability.rs
@@ -664,7 +664,7 @@ pub fn expected_error_kind(message: &str) -> Option<ExpectedErrorKind> {
if is_local_ai_capability_unavailable_message(&lower) {
return Some(ExpectedErrorKind::LocalAiCapabilityUnavailable);
}
- if crate::api::classify::is_budget_exhausted_message(message) {
+ if crate::backend::classify::is_budget_exhausted_message(message) {
return Some(ExpectedErrorKind::BudgetExhausted);
}
if is_backend_unavailable_message(message) {
@@ -3180,7 +3180,7 @@ pub fn is_transient_message_failure(msg: &str) -> bool {
pub const USAGE_PROBE_BACKOFF_PREFIX: &str = "USAGE_PROBE_BACKOFF:";
/// Sentinel prefix on the error string a backend-touching call returns when
-/// the core has no [`BackendTransport`](crate::api::transport::BackendTransport)
+/// the core has no [`BackendTransport`](crate::backend::transport::BackendTransport)
/// installed. `api::rest::flatten_authed_error` and the integrations client
/// build their message from this constant; [`is_backend_unavailable_message`]
/// classifies it as [`ExpectedErrorKind::BackendUnavailable`].
@@ -3482,7 +3482,7 @@ fn event_contains_budget_exhausted_message(event: &sentry::protocol::Event<'_>)
if event
.message
.as_deref()
- .is_some_and(crate::api::classify::is_budget_exhausted_message)
+ .is_some_and(crate::backend::classify::is_budget_exhausted_message)
{
return true;
}
@@ -3491,7 +3491,7 @@ fn event_contains_budget_exhausted_message(event: &sentry::protocol::Event<'_>)
exception
.value
.as_deref()
- .is_some_and(crate::api::classify::is_budget_exhausted_message)
+ .is_some_and(crate::backend::classify::is_budget_exhausted_message)
})
}
diff --git a/crates/openhuman-core/src/core/runtime/builder.rs b/crates/openhuman-core/src/core/runtime/builder.rs
index 52a947fb1f..383cf13069 100644
--- a/crates/openhuman-core/src/core/runtime/builder.rs
+++ b/crates/openhuman-core/src/core/runtime/builder.rs
@@ -462,7 +462,7 @@ pub struct CoreBuilder {
host: Option<String>,
port: Option<u16>,
config: Option<crate::config::Config>,
- backend_transport: Option<std::sync::Arc<dyn crate::api::transport::BackendTransport>>,
+ backend_transport: Option<std::sync::Arc<dyn crate::backend::transport::BackendTransport>>,
}
impl CoreBuilder {
@@ -483,11 +483,11 @@ impl CoreBuilder {
}
/// Bind the transport this core's handlers reach the hosted TinyHumans
- /// backend through (see [`crate::api::transport`]).
+ /// backend through (see [`crate::backend::transport`]).
///
/// Optional: without it the core resolves the process-global transport
/// installed with
- /// [`install_backend_transport`](crate::api::transport::install_backend_transport),
+ /// [`install_backend_transport`](crate::backend::transport::install_backend_transport),
/// and with neither every backend-touching call degrades to a typed
/// "backend unavailable" error while agents, memory, tools and RPC keep
/// working. Library hosts that build one runtime per process prefer this
@@ -496,7 +496,7 @@ impl CoreBuilder {
/// global.
pub fn backend_transport(
mut self,
- transport: std::sync::Arc<dyn crate::api::transport::BackendTransport>,
+ transport: std::sync::Arc<dyn crate::backend::transport::BackendTransport>,
) -> Self {
self.backend_transport = Some(transport);
self
diff --git a/crates/openhuman-core/src/core/runtime/context.rs b/crates/openhuman-core/src/core/runtime/context.rs
index 21274d3f2a..705d0fa946 100644
--- a/crates/openhuman-core/src/core/runtime/context.rs
+++ b/crates/openhuman-core/src/core/runtime/context.rs
@@ -98,10 +98,10 @@ pub struct CoreContext {
/// TinyHumans backend through, when the host supplied one via
/// [`CoreBuilder::backend_transport`](crate::core::runtime::CoreBuilder::backend_transport).
/// `None` means "fall back to the process-global transport" — see
- /// [`crate::api::transport::resolve_backend_transport`] for the order.
+ /// [`crate::backend::transport::resolve_backend_transport`] for the order.
/// Inherited unchanged by every context derived through
/// [`CoreContext::derive_with`].
- backend_transport: Option<Arc<dyn crate::api::transport::BackendTransport>>,
+ backend_transport: Option<Arc<dyn crate::backend::transport::BackendTransport>>,
}
/// Per-agent overrides layered onto a booted context by
@@ -238,7 +238,7 @@ impl CoreContext {
domains: crate::core::runtime::DomainSet,
tool_groups: crate::tools::toolpacks::ToolGroups,
preloaded_config: Option<crate::config::Config>,
- backend_transport: Option<Arc<dyn crate::api::transport::BackendTransport>>,
+ backend_transport: Option<Arc<dyn crate::backend::transport::BackendTransport>>,
) -> anyhow::Result<(Arc<CoreContext>, bool, Option<crate::config::Config>)> {
log::debug!(
"[core-context] init: host_kind={host_kind:?} domains={domains:?} \
@@ -449,7 +449,7 @@ impl CoreContext {
}
/// The backend transport bound to this context, if the host supplied one.
- pub fn backend_transport(&self) -> Option<Arc<dyn crate::api::transport::BackendTransport>> {
+ pub fn backend_transport(&self) -> Option<Arc<dyn crate::backend::transport::BackendTransport>> {
self.backend_transport.clone()
}
diff --git a/crates/openhuman-core/src/core/runtime/services.rs b/crates/openhuman-core/src/core/runtime/services.rs
index 8bb14faa79..7901d322da 100644
--- a/crates/openhuman-core/src/core/runtime/services.rs
+++ b/crates/openhuman-core/src/core/runtime/services.rs
@@ -439,12 +439,12 @@ pub fn spawn_socket_auto_connect(
};
// No TinyHumans connection (no backend transport installed): there
// is no backend to hold a socket to, so skip quietly.
- if !crate::api::transport::is_installed() {
+ if !crate::backend::transport::is_installed() {
log::debug!("[socket] No backend transport installed — skipping auto-connect");
return;
}
let api_url = crate::api::config::effective_backend_api_url(&config.api_url);
- let initial_token = match crate::api::jwt::get_session_token(&config) {
+ let initial_token = match crate::security::credentials::jwt::get_session_token(&config) {
Ok(Some(t))
if crate::security::credentials::session_support::is_local_session_token(
&t,
diff --git a/crates/openhuman-core/src/cron/scheduler/failure_classification.rs b/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
index 277c23dedb..8e4cd4f838 100644
--- a/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
+++ b/crates/openhuman-core/src/cron/scheduler/failure_classification.rs
@@ -186,7 +186,7 @@ pub(super) fn is_budget_exhausted_failure(
return false;
}
let signal = last_agent_error.unwrap_or(last_output);
- crate::api::classify::is_budget_exhausted_message(signal)
+ crate::backend::classify::is_budget_exhausted_message(signal)
}
/// TAURI-RUST-HCK — a cron **agent** job pinned to a provider with no
diff --git a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
index 574fc01685..bb897e5ff9 100644
--- a/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
+++ b/crates/openhuman-core/src/flows/tinyflows/langfuse_export.rs
@@ -48,7 +48,7 @@ const PUSH_TIMEOUT: Duration = Duration::from_secs(10);
/// custom `api_url` override).
fn ingestion_url(config: &Config) -> String {
let base = effective_backend_api_url(&config.api_url);
- crate::api::config::api_url(&base, INGESTION_PATH)
+ crate::util::url::join_url(&base, INGESTION_PATH)
}
/// The OpenHuman core crate version (e.g. `0.58.0`), stamped onto every flow
diff --git a/crates/openhuman-core/src/inference/embedding_host/factory_tests.rs b/crates/openhuman-core/src/inference/embedding_host/factory_tests.rs
index 7bf7db474c..bb126950df 100644
--- a/crates/openhuman-core/src/inference/embedding_host/factory_tests.rs
+++ b/crates/openhuman-core/src/inference/embedding_host/factory_tests.rs
@@ -351,7 +351,7 @@ async fn factory_managed_provider_authenticates_with_config_scoped_token() {
// held under the crate-wide backend-env lock (shared with `api::config`'s
// own BACKEND_URL tests) so the process-global env can't race.
let provider = {
- let _env_guard = crate::api::config::backend_env_test_lock();
+ let _env_guard = crate::config::app_env::env_test_lock();
let prev = std::env::var("BACKEND_URL").ok();
std::env::set_var("BACKEND_URL", &base);
let built = create_embedding_provider_with_config(
@@ -446,7 +446,7 @@ async fn default_provider_with_config_authenticates_with_config_scoped_token() {
.unwrap();
let provider = {
- let _env_guard = crate::api::config::backend_env_test_lock();
+ let _env_guard = crate::config::app_env::env_test_lock();
let prev = std::env::var("BACKEND_URL").ok();
std::env::set_var("BACKEND_URL", &base);
let built = default_embedding_provider_with_config(&config);
diff --git a/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs b/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs
index 23e64658b4..30c3dc54fe 100644
--- a/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs
+++ b/crates/openhuman-core/src/inference/provider/ops/http_error/quota_and_credits.rs
@@ -5,7 +5,7 @@
/// user-state error that should be demoted from Sentry to an info log.
pub fn is_budget_exhausted_http_400(status: reqwest::StatusCode, body: &str) -> bool {
status == reqwest::StatusCode::BAD_REQUEST
- && crate::api::classify::is_budget_exhausted_message(body)
+ && crate::backend::classify::is_budget_exhausted_message(body)
}
pub fn log_budget_exhausted_http_400(
diff --git a/crates/openhuman-core/src/inference/provider/ops/models/catalog_listing.rs b/crates/openhuman-core/src/inference/provider/ops/models/catalog_listing.rs
index de68febc97..64d7f81b10 100644
--- a/crates/openhuman-core/src/inference/provider/ops/models/catalog_listing.rs
+++ b/crates/openhuman-core/src/inference/provider/ops/models/catalog_listing.rs
@@ -184,7 +184,7 @@ pub async fn list_configured_models_from_config(
}
let base = crate::api::config::effective_backend_api_url(&config.api_url);
models_url = append_query_param(
- &crate::api::config::api_url(&base, "/openai/v1/models"),
+ &crate::util::url::join_url(&base, "/openai/v1/models"),
"catalog",
"openrouter",
);
diff --git a/crates/openhuman-core/src/integrations/client/budget_gate.rs b/crates/openhuman-core/src/integrations/client/budget_gate.rs
index 1ee5d17d29..3f75612707 100644
--- a/crates/openhuman-core/src/integrations/client/budget_gate.rs
+++ b/crates/openhuman-core/src/integrations/client/budget_gate.rs
@@ -10,7 +10,7 @@
//! about one probe a minute across both surfaces.
//!
//! The pre-call probe reads `GET /teams/me/usage` through
-//! [`BackendOAuthClient`], so it rides the backend transport port. It resolves
+//! [`BackendClient`], so it rides the backend transport port. It resolves
//! the credential first and defers to the backend (allows the call) without
//! any request when there is no usable TinyHumans credential — the offline
//! local session, an API-less core, or a signed-out user.
@@ -21,7 +21,7 @@ use std::time::{Duration, Instant};
use serde_json::Value;
use crate::api::config::effective_backend_api_url;
-use crate::api::BackendOAuthClient;
+use crate::backend::BackendClient;
use crate::config::Config;
use crate::rpc::RpcOutcome;
use crate::security::credentials::session_support::BackendCredential;
@@ -31,11 +31,11 @@ use crate::security::credentials::session_support::BackendCredential;
/// the `SESSION_EXPIRED` sentinel so a lapse never anchors the backoff.
async fn fetch_usage(config: &Config, credential: BackendCredential) -> Result<Value, String> {
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, reqwest::Method::GET, "/teams/me/usage", None)
.await
- .map_err(crate::api::flatten_authed_error)
+ .map_err(crate::backend::flatten_authed_error)
}
/// How long a *failed* usage fetch is short-circuited before the backend is
diff --git a/crates/openhuman-core/src/integrations/client/construct.rs b/crates/openhuman-core/src/integrations/client/construct.rs
index 4635d5fb23..b07116fc02 100644
--- a/crates/openhuman-core/src/integrations/client/construct.rs
+++ b/crates/openhuman-core/src/integrations/client/construct.rs
@@ -15,9 +15,9 @@ use crate::integrations::types::IntegrationPricing;
/// baked into a build silently produced 404 URLs like
/// `…/openai/v1/chat/completions/agent-integrations/composio/connections`
/// because every `IntegrationClient` method joins paths onto this field
-/// via [`crate::api::config::api_url`].
+/// via [`crate::util::url::join_url`].
pub(super) fn sanitize_backend_url(backend_url: &str) -> String {
- let cleaned = crate::api::config::normalize_backend_api_base_url(backend_url);
+ let cleaned = crate::util::url::normalize_backend_api_base_url(backend_url);
let trimmed = backend_url.trim().trim_end_matches('/');
if !cleaned.is_empty() && cleaned != trimmed {
// Redact userinfo (username/password) before logging — a
@@ -25,8 +25,8 @@ pub(super) fn sanitize_backend_url(backend_url: &str) -> String {
// segment. The helper preserves host/path for diagnosability
// while scrubbing secrets.
tracing::warn!(
- input = %crate::api::config::redact_url_for_log(trimmed),
- cleaned = %crate::api::config::redact_url_for_log(&cleaned),
+ input = %crate::util::redact_url_for_log(trimmed),
+ cleaned = %crate::util::redact_url_for_log(&cleaned),
"[integrations] backend_url carried an inference / non-root path; \
stripping before use (issue #2075)"
);
@@ -40,7 +40,7 @@ pub(super) fn sanitize_backend_url(backend_url: &str) -> String {
/// Shared client for all integration tools. Holds backend URL, auth token,
/// the download `reqwest::Client`, and a lazily-fetched pricing cache. JSON
-/// traffic rides the process [`BackendTransport`](crate::api::transport::BackendTransport).
+/// traffic rides the process [`BackendTransport`](crate::backend::transport::BackendTransport).
pub struct IntegrationClient {
pub backend_url: String,
pub auth_token: String,
diff --git a/crates/openhuman-core/src/integrations/client/download.rs b/crates/openhuman-core/src/integrations/client/download.rs
index db69344634..bf62133ddf 100644
--- a/crates/openhuman-core/src/integrations/client/download.rs
+++ b/crates/openhuman-core/src/integrations/client/download.rs
@@ -2,7 +2,7 @@
//! download route bypasses the JSON envelope and needs `Content-Type` /
//! `Content-Disposition` metadata the SDK's binary primitive doesn't expose.
-use crate::api::transport::BackendTransportError;
+use crate::backend::transport::BackendTransportError;
use super::construct::IntegrationClient;
use super::requests::{emit_backend_egress, enforce_backend_egress};
@@ -64,7 +64,7 @@ impl IntegrationClient {
if !is_file_download {
anyhow::bail!("route is intentionally not exposed by the SDK: GET {route}");
}
- let url = crate::api::config::api_url(&self.backend_url, path);
+ let url = crate::util::url::join_url(&self.backend_url, path);
tracing::debug!("[integrations] GET(bytes) {}", url);
let resp = self
diff --git a/crates/openhuman-core/src/integrations/client/errors.rs b/crates/openhuman-core/src/integrations/client/errors.rs
index 7a22186153..74796299d5 100644
--- a/crates/openhuman-core/src/integrations/client/errors.rs
+++ b/crates/openhuman-core/src/integrations/client/errors.rs
@@ -4,7 +4,7 @@
use std::error::Error as _;
-use crate::api::transport::BackendTransportError;
+use crate::backend::transport::BackendTransportError;
use crate::integrations::types::BackendResponse;
@@ -48,7 +48,7 @@ pub(crate) fn extract_error_detail(body: &str, max_bytes: usize) -> String {
/// **Why this 401 is unambiguously a session-JWT rejection.** Every request
/// from [`IntegrationClient`] attaches the *app-session JWT* as its
/// `Authorization: Bearer` — [`super::construct::IntegrationClient::new`] resolves the
-/// token via [`crate::api::jwt::get_session_token`], the same token billing / team /
+/// token via [`crate::security::credentials::jwt::get_session_token`], the same token billing / team /
/// webhooks / memory all use. The backend's auth middleware
/// (`backend-openhuman`) is what answers `401 {"error":"Invalid token"}` when
/// that JWT is expired / revoked / rotated server-side — see the identical
diff --git a/crates/openhuman-core/src/integrations/client/pricing.rs b/crates/openhuman-core/src/integrations/client/pricing.rs
index 7d61c9ce80..4ebb79622e 100644
--- a/crates/openhuman-core/src/integrations/client/pricing.rs
+++ b/crates/openhuman-core/src/integrations/client/pricing.rs
@@ -79,7 +79,7 @@ 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
+/// - auth token → [`crate::security::credentials::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.
@@ -99,7 +99,7 @@ pub fn build_client(config: &crate::config::Config) -> Option<Arc<IntegrationCli
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) {
+ let session_token = match crate::security::credentials::jwt::get_session_token(config) {
Ok(token) => token,
Err(e) => {
tracing::warn!("[integrations] failed to read session token: {e}");
diff --git a/crates/openhuman-core/src/integrations/client/requests.rs b/crates/openhuman-core/src/integrations/client/requests.rs
index 78ef1d6ece..760fdb9117 100644
--- a/crates/openhuman-core/src/integrations/client/requests.rs
+++ b/crates/openhuman-core/src/integrations/client/requests.rs
@@ -56,8 +56,8 @@ impl IntegrationClient {
method: &str,
path: &str,
url: &str,
- ) -> anyhow::Result<std::sync::Arc<dyn crate::api::transport::BackendTransport>> {
- crate::api::transport::resolve_backend_transport()
+ ) -> anyhow::Result<std::sync::Arc<dyn crate::backend::transport::BackendTransport>> {
+ crate::backend::transport::resolve_backend_transport()
.map_err(|error| Self::map_transport_error(error, method, path, url))
}
@@ -70,9 +70,9 @@ impl IntegrationClient {
method: reqwest::Method,
path: &'a str,
body: Option<&'a serde_json::Value>,
- ) -> crate::api::transport::BackendRequest<'a> {
- crate::api::transport::BackendRequest {
- profile: crate::api::transport::TransportProfile::Integrations,
+ ) -> crate::backend::transport::BackendRequest<'a> {
+ crate::backend::transport::BackendRequest {
+ profile: crate::backend::transport::TransportProfile::Integrations,
base_url: &self.backend_url,
method,
path,
@@ -122,7 +122,7 @@ impl IntegrationClient {
enforce_backend_egress(path)?;
emit_backend_egress(path);
self.ensure_budget_available(path).await?;
- let url = crate::api::config::api_url(&self.backend_url, path);
+ let url = crate::util::url::join_url(&self.backend_url, path);
let method_name = method.as_str().to_ascii_lowercase();
tracing::debug!("[integrations] {} {}", method.as_str(), url);
let value = self
@@ -165,7 +165,7 @@ impl IntegrationClient {
enforce_backend_egress(path)?;
emit_backend_egress(path);
self.ensure_budget_available(path).await?;
- let url = crate::api::config::api_url(&self.backend_url, path);
+ let url = crate::util::url::join_url(&self.backend_url, path);
tracing::debug!("[integrations] POST(multipart) {}", url);
let value = self
diff --git a/crates/openhuman-core/src/integrations/composio/client/connections.rs b/crates/openhuman-core/src/integrations/composio/client/connections.rs
index e83e63cdfc..c588a1487c 100644
--- a/crates/openhuman-core/src/integrations/composio/client/connections.rs
+++ b/crates/openhuman-core/src/integrations/composio/client/connections.rs
@@ -136,7 +136,7 @@ impl ComposioClient {
error: Option<String>,
}
- let url = crate::api::config::api_url(&self.inner.backend_url, path);
+ let url = crate::util::url::join_url(&self.inner.backend_url, path);
tracing::debug!("[composio] DELETE {}", url);
// Build a fresh lightweight reqwest client for this DELETE.
diff --git a/crates/openhuman-core/src/integrations/composio/ops/error_utils.rs b/crates/openhuman-core/src/integrations/composio/ops/error_utils.rs
index 334a1c4f2b..9010293102 100644
--- a/crates/openhuman-core/src/integrations/composio/ops/error_utils.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops/error_utils.rs
@@ -98,7 +98,7 @@ pub(crate) fn direct_mode_without_key(config: &Config) -> OpResult<bool> {
///
/// Session presence MUST mirror the module route's own resolution:
/// `module_config` calls `integrations::build_client`, whose only token source
-/// is the app-session JWT (`crate::api::jwt::get_session_token`). Read that
+/// is the app-session JWT (`crate::security::credentials::jwt::get_session_token`). Read that
/// same source — not `build_client` itself, which logs a warning per call and
/// would recreate the noise this guard removes.
///
@@ -110,7 +110,7 @@ pub(crate) fn backend_mode_without_session(config: &Config) -> bool {
if !(mode.is_empty() || mode == crate::config::schema::COMPOSIO_MODE_BACKEND) {
return false;
}
- match crate::api::jwt::get_session_token(config) {
+ match crate::security::credentials::jwt::get_session_token(config) {
Ok(token) => token.as_deref().map(str::trim).is_none_or(|token| {
token.is_empty()
|| crate::security::credentials::session_support::is_local_session_token(token)
diff --git a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
index 414abeb6be..8e695dae1d 100644
--- a/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
+++ b/crates/openhuman-core/src/integrations/composio/ops_profile_tools_execute_mock_tests.rs
@@ -14,7 +14,7 @@ async fn composio_get_user_profile_via_mock_returns_provider_profile() {
// api::config / core::cli_tests tests
// that mutate the same process-global var under the crate-wide lock —
// TEST_ENV_LOCK alone does not serialize against those. Hold both.
- let _backend_env_guard = crate::api::config::backend_env_test_lock();
+ let _backend_env_guard = crate::config::app_env::env_test_lock();
let app = Router::new()
.route(
diff --git a/crates/openhuman-core/src/media/generation/provider.rs b/crates/openhuman-core/src/media/generation/provider.rs
index 4a254e765d..2f3afe4af4 100644
--- a/crates/openhuman-core/src/media/generation/provider.rs
+++ b/crates/openhuman-core/src/media/generation/provider.rs
@@ -29,7 +29,7 @@ use tinyagents_harness::tinyinference_video::{
};
use crate::api::config::effective_backend_api_url;
-use crate::api::BackendOAuthClient;
+use crate::backend::BackendClient;
use crate::config::Config;
use crate::security::credentials::session_support::{
resolve_backend_credential, BackendCredential,
@@ -49,7 +49,7 @@ pub struct MediaGenerators {
/// Builds generators against the managed backend, or `None` when no backend
/// transport is installed (a core with no TinyHumans connection).
pub fn managed_generators(config: &Config) -> Option<MediaGenerators> {
- let client = match BackendOAuthClient::new(&effective_backend_api_url(&config.api_url)) {
+ let client = match BackendClient::new(&effective_backend_api_url(&config.api_url)) {
Ok(client) => client,
Err(error) => {
tracing::debug!(%error, "[media_generation] invalid backend URL; media tools skipped");
diff --git a/crates/openhuman-core/src/memory/host.rs b/crates/openhuman-core/src/memory/host.rs
index 3020a4ae97..0b3d7a5fc9 100644
--- a/crates/openhuman-core/src/memory/host.rs
+++ b/crates/openhuman-core/src/memory/host.rs
@@ -105,7 +105,7 @@ impl MemoryHostConfig for Config {
}
fn session_token(&self) -> Result<Option<String>, String> {
- crate::api::jwt::get_session_token(self)
+ crate::security::credentials::jwt::get_session_token(self)
}
fn default_model(&self) -> Option<&str> {
diff --git a/crates/openhuman-core/src/modules/memory_host.rs b/crates/openhuman-core/src/modules/memory_host.rs
index d8d909711e..42905a38be 100644
--- a/crates/openhuman-core/src/modules/memory_host.rs
+++ b/crates/openhuman-core/src/modules/memory_host.rs
@@ -301,7 +301,7 @@ impl ComposioCallbacks {
/// differently.
async fn session_bearer(&self) -> tinybus::Result<Option<String>> {
let config = self.live_config_or_installed().await;
- Ok(crate::api::jwt::get_session_token(config.as_ref())
+ Ok(crate::security::credentials::jwt::get_session_token(config.as_ref())
.ok()
.flatten())
}
diff --git a/crates/openhuman-core/src/platform/doctor/core/config_checks.rs b/crates/openhuman-core/src/platform/doctor/core/config_checks.rs
index 90b932cec8..6ebdbdeb3e 100644
--- a/crates/openhuman-core/src/platform/doctor/core/config_checks.rs
+++ b/crates/openhuman-core/src/platform/doctor/core/config_checks.rs
@@ -37,7 +37,7 @@ pub(super) fn check_config_semantics(config: &Config, items: &mut Vec<Diagnostic
));
}
- match crate::api::jwt::get_session_token(config) {
+ match crate::security::credentials::jwt::get_session_token(config) {
Ok(Some(token)) if !token.trim().is_empty() => {
items.push(DiagnosticItem::ok(cat, "signed in with app session JWT"));
}
diff --git a/crates/openhuman-core/src/platform/socket/event_handlers.rs b/crates/openhuman-core/src/platform/socket/event_handlers.rs
index 901327ddb5..8d574d7446 100644
--- a/crates/openhuman-core/src/platform/socket/event_handlers.rs
+++ b/crates/openhuman-core/src/platform/socket/event_handlers.rs
@@ -9,7 +9,7 @@ use std::sync::Arc;
use serde_json::json;
use tokio::sync::mpsc;
-use crate::api::models::socket::ConnectionStatus;
+use crate::platform::socket::models::ConnectionStatus;
use crate::core::bus::BUS;
use crate::core::events::DomainEvent;
use crate::skills::webhooks::WebhookRequest;
diff --git a/crates/openhuman-core/src/platform/socket/manager.rs b/crates/openhuman-core/src/platform/socket/manager.rs
index 707dd21ce0..5d5a340c25 100644
--- a/crates/openhuman-core/src/platform/socket/manager.rs
+++ b/crates/openhuman-core/src/platform/socket/manager.rs
@@ -20,7 +20,7 @@ use serde_json::json;
use tokio::sync::{mpsc, oneshot, watch};
use tokio::time::Duration;
-use crate::api::models::socket::{ConnectionStatus, SocketState};
+use crate::platform::socket::models::{ConnectionStatus, SocketState};
use crate::skills::webhooks::WebhookRouter;
use super::token_provider::{static_token_provider, TokenProvider};
diff --git a/crates/openhuman-core/src/platform/socket/ops.rs b/crates/openhuman-core/src/platform/socket/ops.rs
index 869a94d85d..d5e2b8329c 100644
--- a/crates/openhuman-core/src/platform/socket/ops.rs
+++ b/crates/openhuman-core/src/platform/socket/ops.rs
@@ -1,4 +1,4 @@
-use crate::api::models::socket::SocketState;
+use crate::platform::socket::models::SocketState;
use super::SocketManager;
@@ -53,7 +53,7 @@ pub async fn connect_with_session(manager: &SocketManager) -> Result<SocketState
log::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)
+ let token = crate::security::credentials::jwt::get_session_token(&config)
.map_err(|e| format!("failed to read session token: {e}"))?
.ok_or("no session token stored — user must log in first")?;
diff --git a/crates/openhuman-core/src/platform/socket/schemas.rs b/crates/openhuman-core/src/platform/socket/schemas.rs
index 7be91cffbf..d8eacf4bfd 100644
--- a/crates/openhuman-core/src/platform/socket/schemas.rs
+++ b/crates/openhuman-core/src/platform/socket/schemas.rs
@@ -6,7 +6,7 @@ use crate::core::all::{ControllerFuture, RegisteredController};
use crate::core::{ControllerSchema, FieldSchema, TypeSchema};
use super::manager::global_socket_manager;
-use crate::api::models::socket::{ConnectionStatus, SocketState};
+use crate::platform::socket::models::{ConnectionStatus, SocketState};
// ---------------------------------------------------------------------------
// Schema catalog
diff --git a/crates/openhuman-core/src/platform/socket/token_provider.rs b/crates/openhuman-core/src/platform/socket/token_provider.rs
index 46ed159ded..ad82edced7 100644
--- a/crates/openhuman-core/src/platform/socket/token_provider.rs
+++ b/crates/openhuman-core/src/platform/socket/token_provider.rs
@@ -75,7 +75,7 @@ pub(super) fn static_token_provider(token: String) -> TokenProvider {
/// 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::jwt::get_session_token(&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())
})
diff --git a/crates/openhuman-core/src/platform/socket/types.rs b/crates/openhuman-core/src/platform/socket/types.rs
index 720c53f23b..3b02baa413 100644
--- a/crates/openhuman-core/src/platform/socket/types.rs
+++ b/crates/openhuman-core/src/platform/socket/types.rs
@@ -1,6 +1,6 @@
//! Socket domain types, constants, and re-exports.
-pub use crate::api::models::socket::{ConnectionStatus, SocketState};
+pub use crate::platform::socket::models::{ConnectionStatus, SocketState};
/// Events emitted for observability / frontend bridging.
#[allow(dead_code)]
diff --git a/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs b/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs
index 4f98e3c20f..d746d5bfe1 100644
--- a/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs
+++ b/crates/openhuman-core/src/platform/socket/ws_loop/connect.rs
@@ -15,7 +15,7 @@ use tokio_tungstenite::{
tungstenite::{http::StatusCode, Error as WsError, Message as WsMessage},
};
-use crate::api::models::socket::ConnectionStatus;
+use crate::platform::socket::models::ConnectionStatus;
use crate::util::utf8_safe_prefix_at_byte_boundary;
use super::dispatch::handle_eio_message;
diff --git a/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs b/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs
index aaff387983..b57738b087 100644
--- a/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs
+++ b/crates/openhuman-core/src/platform/socket/ws_loop/reconnect.rs
@@ -9,7 +9,7 @@ use parking_lot::Mutex;
use tokio::sync::{mpsc, watch};
use tokio::time::{Duration, Instant};
-use crate::api::models::socket::ConnectionStatus;
+use crate::platform::socket::models::ConnectionStatus;
use super::connect::{run_connection, ReconnectContext};
use crate::platform::socket::manager::{emit_state_change, SharedState};
@@ -101,7 +101,7 @@ pub(crate) async fn ws_loop(
// BACKEND_URL is configured as `http://` and the edge forces TLS), we
// follow the Location header and pin the resolved URL here so subsequent
// reconnects skip the redirect round-trip entirely.
- let mut ws_url = crate::api::socket::websocket_url(&url);
+ let mut ws_url = crate::platform::socket::url::websocket_url(&url);
// What the next attempt is recovering from, so the handshake can log how
// long the socket was down and how many attempts it took (#6256).
let mut reconnect = ReconnectContext::default();
diff --git a/crates/openhuman-core/src/security/credentials/api_key.rs b/crates/openhuman-core/src/security/credentials/api_key.rs
index 998716b213..917b9bba66 100644
--- a/crates/openhuman-core/src/security/credentials/api_key.rs
+++ b/crates/openhuman-core/src/security/credentials/api_key.rs
@@ -9,7 +9,7 @@
//! `Authorization: Bearer <key>` — the OpenAI-compatible endpoint takes a
//! bearer, and `OpenHumanBackendModel::resolve_bearer` prefers this profile
//! over the app session;
-//! * SDK REST clients send it as `x-api-key` — `BackendOAuthClient` and
+//! * SDK REST clients send it as `x-api-key` — `BackendClient` and
//! `IntegrationClient` pick the header from [`BackendCredential`].
//!
//! The key lives in the same auth-profile store as the app session (the
diff --git a/crates/openhuman-core/src/security/credentials/bus.rs b/crates/openhuman-core/src/security/credentials/bus.rs
index 5a60584fab..32037958df 100644
--- a/crates/openhuman-core/src/security/credentials/bus.rs
+++ b/crates/openhuman-core/src/security/credentials/bus.rs
@@ -75,7 +75,7 @@ impl EventHandler<DomainEvent> for SessionExpiredSubscriber {
scheduler_gate::set_signed_out(false);
return;
}
- let is_local_session = crate::api::jwt::get_session_token(&config)
+ let is_local_session = crate::security::credentials::jwt::get_session_token(&config)
.ok()
.flatten()
.is_some_and(|token| {
diff --git a/crates/openhuman-core/src/security/credentials/mod.rs b/crates/openhuman-core/src/security/credentials/mod.rs
index c60394e064..56662c6f0c 100644
--- a/crates/openhuman-core/src/security/credentials/mod.rs
+++ b/crates/openhuman-core/src/security/credentials/mod.rs
@@ -15,8 +15,8 @@ pub mod sentry_scope;
pub mod session_support;
pub mod tools;
-pub use crate::api::rest::{
- decrypt_handoff_blob, user_id_from_profile_payload, BackendOAuthClient,
+pub use crate::backend::{
+ decrypt_handoff_blob, user_id_from_profile_payload, BackendClient,
};
pub use core::*;
pub use credential_ref::{CredentialRef, CredentialRefError, CredentialRefScheme, ResolvedSecret};
diff --git a/crates/openhuman-core/src/security/credentials/ops/credential.rs b/crates/openhuman-core/src/security/credentials/ops/credential.rs
index 563f3cc8bf..2e8c981f40 100644
--- a/crates/openhuman-core/src/security/credentials/ops/credential.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/credential.rs
@@ -12,7 +12,7 @@
use serde::Deserialize;
use serde_json::{json, Value};
-use crate::api::jwt::decode_jwt_exp;
+use crate::security::credentials::jwt::decode_jwt_exp;
use crate::config::Config;
use crate::rpc::RpcOutcome;
use crate::security::credentials::responses::AuthStateResponse;
@@ -77,7 +77,7 @@ fn sanitize_user(user: Option<Value>) -> Option<Value> {
}
fn user_id_from_payload(user: Option<&Value>) -> Option<String> {
- user.and_then(crate::api::rest::user_id_from_profile_payload)
+ user.and_then(crate::backend::user_id_from_profile_payload)
}
fn normalize_local_user(user: Value, local_user_id: &str) -> Value {
diff --git a/crates/openhuman-core/src/security/credentials/ops/oauth.rs b/crates/openhuman-core/src/security/credentials/ops/oauth.rs
index 2c5d3c2a0f..a9bfc526e8 100644
--- a/crates/openhuman-core/src/security/credentials/ops/oauth.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/oauth.rs
@@ -11,8 +11,8 @@
use serde_json::json;
use crate::api::config::effective_backend_api_url;
-use crate::api::jwt::get_session_token;
-use crate::api::rest::BackendOAuthClient;
+use crate::security::credentials::jwt::get_session_token;
+use crate::backend::BackendClient;
use crate::config::Config;
use crate::rpc::RpcOutcome;
@@ -22,13 +22,13 @@ pub async fn oauth_fetch_client_key(
) -> Result<RpcOutcome<serde_json::Value>, String> {
let api_url = effective_backend_api_url(&config.api_url);
let token = get_session_token(config)?.ok_or_else(|| "session JWT required".to_string())?;
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
// `flatten_authed_error` keeps a 401 on the `SESSION_EXPIRED` sentinel (and
// a missing transport on `BACKEND_UNAVAILABLE:`) instead of an opaque string.
let client_key = client
.fetch_client_key(integration_id, &token)
.await
- .map_err(crate::api::flatten_authed_error)?;
+ .map_err(crate::backend::flatten_authed_error)?;
log::debug!(
"[credentials] client key retrieved for integration {}",
integration_id
diff --git a/crates/openhuman-core/src/security/credentials/ops/session_query.rs b/crates/openhuman-core/src/security/credentials/ops/session_query.rs
index 9eb73977df..0216caf4ed 100644
--- a/crates/openhuman-core/src/security/credentials/ops/session_query.rs
+++ b/crates/openhuman-core/src/security/credentials/ops/session_query.rs
@@ -2,7 +2,7 @@
use serde_json::json;
-use crate::api::jwt::get_session_token;
+use crate::security::credentials::jwt::get_session_token;
use crate::config::Config;
use crate::rpc::RpcOutcome;
use crate::security::credentials::session_support::build_session_state;
diff --git a/crates/openhuman-core/src/security/credentials/session_support.rs b/crates/openhuman-core/src/security/credentials/session_support.rs
index 30927f49e1..f2078e2577 100644
--- a/crates/openhuman-core/src/security/credentials/session_support.rs
+++ b/crates/openhuman-core/src/security/credentials/session_support.rs
@@ -192,7 +192,7 @@ impl CredentialKind {
/// The subject of a JWT, read from its payload claims without verification.
/// Checked in order: `sub`, `userId`, `user_id`, `_id`, `id`.
pub fn user_id_from_jwt_claims(token: &str) -> Option<String> {
- let claims = crate::api::jwt::decode_jwt_payload(token)?;
+ let claims = crate::security::credentials::jwt::decode_jwt_payload(token)?;
let obj = claims.as_object()?;
["sub", "userId", "user_id", "_id", "id"]
.iter()
@@ -405,7 +405,7 @@ pub fn resolve_backend_credential(config: &Config) -> Result<BackendCredential,
/// Both are configured states, not faults, so the skip is logged at `debug`
/// with `op` naming the caller; nothing reaches Sentry and no request is made.
pub fn direct_backend_credential(config: &Config, op: &str) -> Option<BackendCredential> {
- if !crate::api::transport::is_installed() {
+ if !crate::backend::transport::is_installed() {
log::debug!("[backend-direct] {op} skipped: no backend transport installed");
return None;
}
diff --git a/crates/openhuman-core/src/security/credentials/session_support_tests.rs b/crates/openhuman-core/src/security/credentials/session_support_tests.rs
index 967471190f..124d988940 100644
--- a/crates/openhuman-core/src/security/credentials/session_support_tests.rs
+++ b/crates/openhuman-core/src/security/credentials/session_support_tests.rs
@@ -428,7 +428,7 @@ fn direct_backend_credential_returns_a_live_session() {
)
.unwrap();
// Unit tests resolve the plain test transport, so the transport gate passes.
- assert!(crate::api::transport::is_installed());
+ assert!(crate::backend::transport::is_installed());
assert_eq!(
direct_backend_credential(&config, "test"),
Some(BackendCredential::Session("raw-session-token".into()))
diff --git a/crates/openhuman-core/src/voice/cloud_transcribe.rs b/crates/openhuman-core/src/voice/cloud_transcribe.rs
index 37710f92a5..24a31fb7ee 100644
--- a/crates/openhuman-core/src/voice/cloud_transcribe.rs
+++ b/crates/openhuman-core/src/voice/cloud_transcribe.rs
@@ -1,8 +1,8 @@
//! OpenHuman authentication adapter for hosted speech-to-text.
use crate::api::config::effective_backend_api_url;
-use crate::api::jwt::get_session_token;
-use crate::api::BackendOAuthClient;
+use crate::security::credentials::jwt::get_session_token;
+use crate::backend::BackendClient;
use crate::config::Config;
use crate::rpc::RpcOutcome;
@@ -25,14 +25,14 @@ pub async fn transcribe_cloud(
.to_string(),
);
}
- let client = BackendOAuthClient::new(&effective_backend_api_url(&config.api_url))
+ let client = BackendClient::new(&effective_backend_api_url(&config.api_url))
.map_err(|error| error.to_string())?;
let url = client
.url_for("/openai/v1/audio/transcriptions")
.map_err(|error| error.to_string())?;
let http = client
.raw_client()
- .map_err(crate::api::flatten_authed_error)?;
+ .map_err(crate::backend::flatten_authed_error)?;
let result = tinyinference_voice::cloud::transcribe(&http, url, &token, audio_base64, options)
.await
.map_err(classify_transcribe_error)?;
diff --git a/crates/openhuman-core/src/voice/realtime.rs b/crates/openhuman-core/src/voice/realtime.rs
index f16173550e..19a50d976b 100644
--- a/crates/openhuman-core/src/voice/realtime.rs
+++ b/crates/openhuman-core/src/voice/realtime.rs
@@ -14,8 +14,8 @@ use serde::{Deserialize, Serialize};
use serde_json::Value;
use crate::api::config::effective_backend_api_url;
-use crate::api::jwt::get_session_token;
-use crate::api::BackendOAuthClient;
+use crate::security::credentials::jwt::get_session_token;
+use crate::backend::BackendClient;
use crate::config::Config;
use crate::rpc::RpcOutcome;
@@ -77,7 +77,7 @@ fn authority_host(rest: &str) -> &str {
/// Mint a realtime voice-agent signed URL by proxying the hosted backend.
///
/// Follows the `reply_speech::synthesize_reply` auth pattern: session token →
-/// [`BackendOAuthClient`] → `authed_json`, with `flatten_authed_error` so a
+/// [`BackendClient`] → `authed_json`, with `flatten_authed_error` so a
/// lapsed-session 401 classifies as `SESSION_EXPIRED` and skips Sentry rather
/// than leaking as a raw error string.
pub async fn mint_voice_agent_signed_url(
@@ -97,12 +97,12 @@ pub async fn mint_voice_agent_signed_url(
let api_url = effective_backend_api_url(&config.api_url);
ensure_secure_backend_url(&api_url)?;
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
let raw = client
.authed_json(&token, Method::GET, "/voice-agent/get-signed-url", None)
.await
- .map_err(crate::api::flatten_authed_error)?;
+ .map_err(crate::backend::flatten_authed_error)?;
let result = parse_signed_url_response(&raw)?;
debug!("{LOG_PREFIX} minted signed url agent={}", result.agent_id);
diff --git a/crates/openhuman-core/src/voice/reply_speech.rs b/crates/openhuman-core/src/voice/reply_speech.rs
index 2c86479f31..4779e2098f 100644
--- a/crates/openhuman-core/src/voice/reply_speech.rs
+++ b/crates/openhuman-core/src/voice/reply_speech.rs
@@ -21,8 +21,8 @@ use serde::{Deserialize, Serialize};
use serde_json::{json, Value};
use crate::api::config::effective_backend_api_url;
-use crate::api::jwt::get_session_token;
-use crate::api::BackendOAuthClient;
+use crate::security::credentials::jwt::get_session_token;
+use crate::backend::BackendClient;
use crate::config::Config;
use crate::rpc::RpcOutcome;
@@ -118,7 +118,7 @@ pub struct ReplySpeechOptions {
/// Synthesize the agent's reply through the hosted backend.
///
-/// Uses [`BackendOAuthClient`] for the same reason `referral` does: the
+/// Uses [`BackendClient`] for the same reason `referral` does: the
/// desktop WebView's `fetch` to the backend can fail with an opaque
/// "Load failed" (CORS/TLS quirks), and routing through the core gives us
/// a consistent auth + retry surface.
@@ -170,7 +170,7 @@ pub async fn synthesize_reply(
.ok_or_else(|| "no backend session token; sign in first".to_string())?;
let api_url = effective_backend_api_url(&config.api_url);
- let client = BackendOAuthClient::new(&api_url).map_err(|e| e.to_string())?;
+ let client = BackendClient::new(&api_url).map_err(|e| e.to_string())?;
let mut body = serde_json::Map::new();
body.insert("text".to_string(), json!(trimmed));
@@ -228,7 +228,7 @@ pub async fn synthesize_reply(
Some(Value::Object(body)),
)
.await
- .map_err(crate::api::flatten_authed_error)?;
+ .map_err(crate::backend::flatten_authed_error)?;
let result = normalize_response(&raw);
debug!(
diff --git a/crates/openhuman-core/src/voice/reply_speech_tests.rs b/crates/openhuman-core/src/voice/reply_speech_tests.rs
index 5a325d5d38..aa4d696d86 100644
--- a/crates/openhuman-core/src/voice/reply_speech_tests.rs
+++ b/crates/openhuman-core/src/voice/reply_speech_tests.rs
@@ -140,7 +140,7 @@ fn tts_unauthorized_flattens_to_session_expiry_not_hard_error() {
// `e.to_string()`, producing the raw "backend rejected session token …"
// Display string that matched none of the session-expiry classifiers and
// leaked to Sentry as a hard error. `synthesize_reply` now flattens the
- // typed `BackendApiError::Unauthorized` via `crate::api::flatten_authed_error`
+ // typed `BackendApiError::Unauthorized` via `crate::backend::flatten_authed_error`
// (the #3384 team/billing pattern), so it carries the SESSION_EXPIRED
// sentinel and is recognised + demoted by the JSON-RPC dispatcher.
//
@@ -148,8 +148,8 @@ fn tts_unauthorized_flattens_to_session_expiry_not_hard_error() {
// classifier: build the typed error → flatten → classify. If either the
// sentinel mapping or the classifier drifts, this fails instead of
// silently re-leaking the TTS 401.
- let flat = crate::api::flatten_authed_error(anyhow::Error::new(
- crate::api::BackendApiError::Unauthorized {
+ let flat = crate::backend::flatten_authed_error(anyhow::Error::new(
+ crate::backend::BackendApiError::Unauthorized {
method: "POST".to_string(),
path: "/openai/v1/audio/speech".to_string(),
},
@@ -174,7 +174,7 @@ fn tts_unauthorized_flattens_to_session_expiry_not_hard_error() {
fn tts_non_auth_error_is_not_demoted_to_session_expiry() {
// A genuine TTS failure (timeout, 5xx, …) must keep its full anyhow chain
// and NOT be demoted — real backend/TTS breakage must still reach Sentry.
- let flat = crate::api::flatten_authed_error(
+ let flat = crate::backend::flatten_authed_error(
anyhow::anyhow!("connect timeout").context("backend request POST /openai/v1/audio/speech"),
);
diff --git a/crates/openhuman-core/src/web_chat/web_errors/budget.rs b/crates/openhuman-core/src/web_chat/web_errors/budget.rs
index 730547ea69..980813a017 100644
--- a/crates/openhuman-core/src/web_chat/web_errors/budget.rs
+++ b/crates/openhuman-core/src/web_chat/web_errors/budget.rs
@@ -34,7 +34,7 @@ pub(crate) fn is_inference_budget_exceeded_error(message: &str) -> bool {
// (issue #3088). Without this, an Ollama user with zero credits and
// routing still on Managed sees an opaque "provider error" and has no
// way to self-diagnose that they must top up or switch routing.
- crate::api::classify::is_budget_exhausted_message(message)
+ crate::backend::classify::is_budget_exhausted_message(message)
}
pub(crate) fn inference_budget_exceeded_user_message() -> &'static str {