Skip to content

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

feat(openhuman-tinyhumans): add crate manifest and update runtime config type

Steven Enamakel165211ccbaec
diff --git a/Cargo.lock b/Cargo.lock
index 1b0c9bbd2a..5bf37247c0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4257,6 +4257,25 @@ dependencies = [
"url",
]
+[[package]]
+name = "openhuman-tinyhumans"
+version = "0.63.29"
+dependencies = [
+ "anyhow",
+ "async-trait",
+ "log",
+ "openhuman",
+ "openhuman-embed",
+ "reqwest",
+ "serde",
+ "serde_json",
+ "tempfile",
+ "thiserror 2.0.20",
+ "tinyhumans-sdk",
+ "tokio",
+ "wiremock",
+]
+
[[package]]
name = "openhuman-tui"
version = "0.63.29"
diff --git a/crates/openhuman-tinyhumans/README.md b/crates/openhuman-tinyhumans/README.md
new file mode 100644
index 0000000000..40e720e305
--- /dev/null
+++ b/crates/openhuman-tinyhumans/README.md
@@ -0,0 +1,65 @@
+# openhuman-tinyhumans
+
+OpenHuman on the hosted TinyHumans backend.
+
+```
+openhuman-core ──► knows the backend only through `api::transport::BackendTransport`
+ ▲
+openhuman-embed ──► library facade (Runtime → Agent)
+ ▲
+openhuman-tinyhumans ──► implements the port with the vendored tinyhumans-sdk
+```
+
+The core has **no** `tinyhumans-sdk` dependency. Built and run on its own it
+has no TinyHumans connection: agents, memory, skills, tools and RPC work, and
+every hosted-backend surface (billing, `/agent-integrations/*` tools, channel
+relay, cloud voice) answers with a typed `BACKEND_UNAVAILABLE:` error that
+observability demotes. This crate is what turns that into a connected
+runtime.
+
+## Use
+
+Library hosts:
+
+```rust
+use openhuman_tinyhumans::{embed::Workspace, RuntimeBuilder};
+
+let runtime = RuntimeBuilder::new()
+ .workspace(Workspace::Ephemeral)
+ .api_key("th_...")
+ .build()
+ .await?;
+```
+
+`RuntimeBuilder` mirrors `openhuman_embed::RuntimeBuilder` method for method
+and, on `build()`, installs the SDK transport and binds it to the runtime.
+
+Hosts that boot the core themselves (desktop shell, TUI, CLI, test fixtures)
+call `install` once before the first backend-touching dispatch:
+
+```rust
+openhuman_tinyhumans::install(openhuman_tinyhumans::InstallOptions::default())?;
+```
+
+## What lives here
+
+| Module | Owns |
+| --- | --- |
+| `transport` | `SdkBackendTransport`: one `reqwest::Client` per `TransportProfile`, built from the core's `api::headers` so TLS, timeouts and `x-core-version` / `x-tauri-version` / `x-sdk-name` are exactly what the core specifies; SDK route policy; `tinyhumans_sdk::Error` → `BackendTransportError` |
+| `install` | process-global installation, idempotent |
+| `RuntimeBuilder` | embed builder + transport |
+| `jwt` | the SDK's JWT readers, for hosts that already depend on this crate |
+
+Routes and error classification stay in the core (`api/rest.rs`,
+`integrations/client/`); this crate never adds a route the core does not
+already name.
+
+## Tests
+
+```bash
+cargo test -p openhuman-tinyhumans
+```
+
+`transport_tests.rs` pins the wire shape the core's classifiers depend on
+(bearer vs `x-api-key`, attribution headers, `Status` / `Envelope` mapping,
+SDK route refusal) against a wiremock backend.
diff --git a/crates/openhuman-tinyhumans/src/runtime.rs b/crates/openhuman-tinyhumans/src/runtime.rs
index 7d14f94b51..a8fba3ee84 100644
--- a/crates/openhuman-tinyhumans/src/runtime.rs
+++ b/crates/openhuman-tinyhumans/src/runtime.rs
@@ -8,7 +8,7 @@
use std::sync::Arc;
use openhuman_embed::{
- Access, ApiKey, Config, DomainSet, HostKind, Provider, Runtime, ServiceSet, Session,
+ Access, ApiKey, DomainSet, HostKind, Provider, Runtime, RuntimeConfig, ServiceSet, Session,
ToolGroups, Workspace,
};
@@ -113,7 +113,7 @@ impl RuntimeBuilder {
}
/// See [`openhuman_embed::RuntimeBuilder::config`].
- pub fn config(mut self, config: Config) -> Self {
+ pub fn config(mut self, config: RuntimeConfig) -> Self {
self.inner = self.inner.config(config);
self
}
diff --git a/crates/openhuman-tinyhumans/src/transport/transport_tests.rs b/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
new file mode 100644
index 0000000000..8bcfeea2ad
--- /dev/null
+++ b/crates/openhuman-tinyhumans/src/transport/transport_tests.rs
@@ -0,0 +1,214 @@
+//! Wire-shape parity for the SDK transport: what the core's classification
+//! code relies on, pinned against a mock backend.
+
+use super::*;
+use openhuman_core::api::transport::{clear_backend_transport, resolve_backend_transport};
+use serde_json::json;
+use wiremock::matchers::{header, header_exists, method, path};
+use wiremock::{Mock, MockServer, ResponseTemplate};
+
+fn request<'a>(
+ base: &'a str,
+ method: reqwest::Method,
+ path: &'a str,
+ credential: Option<&'a BackendCredential>,
+ unwrap: bool,
+) -> BackendRequest<'a> {
+ BackendRequest {
+ profile: TransportProfile::Api,
+ base_url: base,
+ method,
+ path,
+ query: &[],
+ body: None,
+ credential,
+ unwrap_envelope: unwrap,
+ }
+}
+
+#[tokio::test]
+async fn session_credential_rides_bearer_with_sdk_and_product_headers() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/teams/me/usage"))
+ .and(header("authorization", "Bearer jwt.a.b"))
+ .and(header("x-sdk-client", "tinyhumans-rust"))
+ .and(header("x-sdk-name", "openhuman"))
+ .and(header_exists("x-core-version"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({
+ "success": true,
+ "data": {"remainingUsd": 1.5}
+ })))
+ .expect(1)
+ .mount(&server)
+ .await;
+
+ let transport = SdkBackendTransport::new().unwrap();
+ let credential = BackendCredential::Session("jwt.a.b\n".into());
+ let value = transport
+ .send_json(request(
+ &server.uri(),
+ reqwest::Method::GET,
+ "/teams/me/usage",
+ Some(&credential),
+ true,
+ ))
+ .await
+ .unwrap();
+ assert_eq!(value, json!({"remainingUsd": 1.5}));
+}
+
+#[tokio::test]
+async fn api_key_credential_rides_x_api_key_and_never_authorization() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/payments/summary"))
+ .and(header("x-api-key", "th_key"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({"ok": true})))
+ .expect(1)
+ .mount(&server)
+ .await;
+
+ let transport = SdkBackendTransport::new().unwrap();
+ let credential = BackendCredential::ApiKey("th_key".into());
+ let value = transport
+ .send_json(request(
+ &server.uri(),
+ reqwest::Method::GET,
+ "/payments/summary",
+ Some(&credential),
+ true,
+ ))
+ .await
+ .unwrap();
+ assert_eq!(value, json!({"ok": true}));
+ let received = server.received_requests().await.unwrap();
+ assert!(received[0].headers.get("authorization").is_none());
+}
+
+#[tokio::test]
+async fn non_2xx_maps_to_status_with_parsed_body() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/x"))
+ .respond_with(ResponseTemplate::new(401).set_body_json(json!({"error": "Invalid token"})))
+ .mount(&server)
+ .await;
+
+ let transport = SdkBackendTransport::new().unwrap();
+ let err = transport
+ .send_json(request(&server.uri(), reqwest::Method::GET, "/x", None, true))
+ .await
+ .unwrap_err();
+ assert!(matches!(
+ err,
+ BackendTransportError::Status { status: 401, ref body } if body == &json!({"error": "Invalid token"})
+ ));
+}
+
+#[tokio::test]
+async fn failed_envelope_on_2xx_maps_to_envelope_error() {
+ let server = MockServer::start().await;
+ Mock::given(method("POST"))
+ .and(path("/y"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({
+ "success": false,
+ "error": "Toolkit X is not enabled",
+ "errorCode": "TOOLKIT_DISABLED"
+ })))
+ .mount(&server)
+ .await;
+
+ let transport = SdkBackendTransport::new().unwrap();
+ let err = transport
+ .send_json(request(&server.uri(), reqwest::Method::POST, "/y", None, true))
+ .await
+ .unwrap_err();
+ match err {
+ BackendTransportError::Envelope {
+ error, error_code, ..
+ } => {
+ assert_eq!(error, "Toolkit X is not enabled");
+ assert_eq!(error_code.as_deref(), Some("TOOLKIT_DISABLED"));
+ }
+ other => panic!("expected Envelope, got {other:?}"),
+ }
+}
+
+#[tokio::test]
+async fn raw_envelope_is_returned_when_not_unwrapping() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/agent-integrations/pricing"))
+ .respond_with(
+ ResponseTemplate::new(200).set_body_json(json!({"success": true, "data": {"a": 1}})),
+ )
+ .mount(&server)
+ .await;
+
+ let transport = SdkBackendTransport::new().unwrap();
+ let value = transport
+ .send_json(request(
+ &server.uri(),
+ reqwest::Method::GET,
+ "/agent-integrations/pricing",
+ None,
+ false,
+ ))
+ .await
+ .unwrap();
+ assert_eq!(value, json!({"success": true, "data": {"a": 1}}));
+}
+
+#[tokio::test]
+async fn sdk_route_policy_refuses_unexposed_routes_before_sending() {
+ let server = MockServer::start().await;
+ let transport = SdkBackendTransport::new().unwrap();
+ let err = transport
+ .send_json(request(
+ &server.uri(),
+ reqwest::Method::GET,
+ "/webhooks/core",
+ None,
+ true,
+ ))
+ .await
+ .unwrap_err();
+ assert!(matches!(err, BackendTransportError::RouteNotExposed(m, p) if m == "GET" && p.contains("webhooks")));
+ assert!(server.received_requests().await.unwrap().is_empty());
+}
+
+#[tokio::test]
+async fn install_makes_the_core_resolve_this_transport() {
+ // Serialised through the install slot; the core's global is process state.
+ let _t = crate::install(crate::InstallOptions::default()).unwrap();
+ assert!(crate::is_installed());
+ assert_eq!(resolve_backend_transport().unwrap().name(), "tinyhumans-sdk");
+ clear_backend_transport();
+ assert!(!crate::is_installed());
+ // Re-install after a clear restores the same transport.
+ let _t = crate::install(crate::InstallOptions::default()).unwrap();
+ assert_eq!(resolve_backend_transport().unwrap().name(), "tinyhumans-sdk");
+}
+
+#[tokio::test]
+async fn backend_client_round_trips_through_the_installed_transport() {
+ let server = MockServer::start().await;
+ Mock::given(method("GET"))
+ .and(path("/announcements/latest"))
+ .and(header("authorization", "Bearer jwt"))
+ .respond_with(ResponseTemplate::new(200).set_body_json(json!({
+ "success": true,
+ "data": {"id": "a1"}
+ })))
+ .mount(&server)
+ .await;
+
+ let _t = crate::install(crate::InstallOptions::default()).unwrap();
+ let client = openhuman_core::api::BackendOAuthClient::new(&server.uri()).unwrap();
+ let value = client
+ .authed_json("jwt", reqwest::Method::GET, "/announcements/latest", None)
+ .await
+ .unwrap();
+ assert_eq!(value, json!({"id": "a1"}));
+}