The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.
Rust agent-orchestrationai-agentsai-assistantdesktopllmlocal-firstmcppersonal-aiprivacyrustsecond-braintauri
chore: files changed crates/openhuman-core/src/channels/host/adapters.rs,crates/openhuman-core/src/i
Steven Enamakel0e48e1dda2d9
diff --git a/crates/openhuman-core/src/channels/host/adapters.rs b/crates/openhuman-core/src/channels/host/adapters.rsindex a7dbe35444..7819c07f11 100644--- a/crates/openhuman-core/src/channels/host/adapters.rs+++ b/crates/openhuman-core/src/channels/host/adapters.rs@@ -142,6 +142,7 @@ impl SpeechSynthesizer for VoiceSynthesizer {// under the `cloud` slug; with none registered this is an error.#[cfg(feature = "voice")]{+ use crate::voice::TtsProvider as _;let voice = request.voice.as_deref().unwrap_or_default();let provider = crate::voice::create_tts_provider("cloud", voice, &self.config)?;let outcome = providerdiff --git a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rsindex 80c54fc87d..fe7185b999 100644--- a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs+++ b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs@@ -1,136 +1,70 @@-//! OpenHuman credential adapter for tinyagents cloud embeddings.+//! Credential scope and the unavailable placeholder for the managed cloud+//! embedder. The embedder itself is a registered provider+//! ([`crate::inference::registry::register_embedding`]); with none registered+//! the managed embedder is a placeholder that answers `BACKEND_UNAVAILABLE:`.use std::path::PathBuf;-use std::sync::Arc;use tinyinference_embeddings::{- BearerResolver, CloudEmbeddingModel, EmbeddingModel, DEFAULT_CLOUD_DIMENSIONS,- DEFAULT_CLOUD_MODEL,+ EmbeddingModel, DEFAULT_CLOUD_DIMENSIONS, DEFAULT_CLOUD_MODEL,};-use crate::security::approval::ApprovalChatContext;-use crate::security::credentials::{AuthService, APP_SESSION_PROVIDER};-pub const DEFAULT_CLOUD_EMBEDDING_MODEL: &str = DEFAULT_CLOUD_MODEL;pub const DEFAULT_CLOUD_EMBEDDING_DIMENSIONS: usize = DEFAULT_CLOUD_DIMENSIONS;-/// Host-owned credential resolution and egress disclosure around the-/// crate-owned cloud transport.-///-/// The egress guard (policy check, then the `ExternalTransferPending`-/// disclosure) runs here, before the batch reaches the transport, so it can-/// carry the chat of the turn that made the call: an embedder built for a chat-/// turn is [`routed_to`](Self::routed_to) that chat and its disclosure surfaces-/// there. One built without a chat (background sync, the embedding RPC) still-/// discloses, unrouted. Nothing reads the chat from the running task.-pub struct OpenHumanCloudEmbeddingModel {- inner: Arc<CloudEmbeddingModel>,+/// The managed embedder when no provider is registered for it: keeps the+/// configured identity (name, model, dimensions) so callers that only describe+/// the embedder still work, and refuses to embed with the `BACKEND_UNAVAILABLE:`+/// sentinel.+pub struct UnavailableEmbeddingModel {model: String,- chat: Option<ApprovalChatContext>,+ dimensions: usize,}-impl OpenHumanCloudEmbeddingModel {- pub fn new(- api_url: Option<String>,- openhuman_dir: Option<PathBuf>,- secrets_encrypt: bool,- model: impl Into<String>,- dimensions: usize,- ) -> Self {- let state_dir = openhuman_dir.unwrap_or_else(default_state_dir);- let base = crate::backend::inference_base_url(&api_url).ok();- let backend_available = base.is_some();- let base_url = format!(- "{}/openai/v1",- base.unwrap_or_default().trim_end_matches('/')- );- let key_endpoint = base_url.clone();- let bearer: BearerResolver = Arc::new(move || {- if !backend_available {- return Err(tinyinference_embeddings::Error::Validation(format!(- "{} managed embeddings need a backend transport",- crate::core::observability::BACKEND_UNAVAILABLE_PREFIX- )));- }- // A stored TinyHumans API key is the bearer outright, exactly as- // for managed inference (`OpenHumanBackendModel::resolve_bearer`):- // `/openai/v1/embeddings` accepts it as `Bearer <key>`. Same- // plaintext guard too — never put the key on a non-HTTPS,- // non-loopback wire.- if let Some(key) =- crate::security::credentials::api_key::get_api_key_in(&state_dir, secrets_encrypt)- .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?- {- if !crate::inference::provider::openhuman_backend_model::is_managed_endpoint_for_api_key(- &key_endpoint,- ) {- return Err(tinyinference_embeddings::Error::Validation(format!(- "refusing to send the TinyHumans API key over a non-HTTPS, non-loopback \- endpoint: {key_endpoint}"- )));- }- log::debug!("[embeddings::cloud] authenticating with api-key");- return Ok(key);- }- let auth = AuthService::new(&state_dir, secrets_encrypt);- auth.get_provider_bearer_token(APP_SESSION_PROVIDER, None)- .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?- .filter(|token| !token.trim().is_empty())- .ok_or_else(|| {- tinyinference_embeddings::Error::Validation(- "No backend session for cloud embeddings: log in to OpenHuman or set a \- TinyHumans API key"- .into(),- )- })- });- let model = model.into();+impl UnavailableEmbeddingModel {+ pub fn new(model: &str, dimensions: usize) -> Self {Self {- inner: Arc::new(CloudEmbeddingModel::new(- base_url,- model.clone(),- dimensions,- bearer,- )),- model,- chat: None,+ model: model.to_string(),+ dimensions,}}+}- /// This embedder with its egress disclosures routed to `chat` (the turn's- /// thread and client); `None` leaves them unrouted. Shares the transport,- /// so it is cheap to do per turn.- #[must_use]- pub fn routed_to(&self, chat: Option<ApprovalChatContext>) -> Self {- Self {- inner: Arc::clone(&self.inner),- model: self.model.clone(),- chat,- }+#[async_trait::async_trait]+impl EmbeddingModel for UnavailableEmbeddingModel {+ fn name(&self) -> &str {+ "cloud"}- /// The egress guard: the privacy policy may refuse the transfer, and an- /// allowed one is disclosed to the chat this embedder is routed to.- fn guard(&self) -> tinyinference_embeddings::Result<()> {- let egress = crate::security::egress::EgressDescriptor::embedding("cloud", &self.model);- crate::security::egress::enforce_egress(&egress)- .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?;- crate::security::egress::emit_external_transfer(self.chat.as_ref(), egress);- Ok(())+ fn model_id(&self) -> &str {+ &self.model}- pub fn from_config(config: &crate::config::Config, model: &str, dimensions: usize) -> Self {- Self::new(- config.api_url.clone(),- Some(crate::security::credentials::state_dir_from_config(config)),- config.secrets.encrypt,- model,- dimensions,- )+ fn dimensions(&self) -> usize {+ self.dimensions}- pub fn new_default_scope(model: &str, dimensions: usize) -> Self {- Self::new(None, None, true, model, dimensions)+ fn signature(&self) -> String {+ format!("unavailable:{}:{}", self.model, self.dimensions)+ }++ async fn embed(&self, _texts: &[String]) -> tinyinference_embeddings::Result<Vec<Vec<f32>>> {+ Err(tinyinference_embeddings::Error::Validation(format!(+ "{} managed embeddings need a hosted provider; none is registered",+ crate::core::observability::BACKEND_UNAVAILABLE_PREFIX+ )))+ }+}++/// The credential directory and encryption flag for a managed embedder:+/// the config's scope when the caller has one, else the process default.+pub(super) fn credential_scope(config: Option<&crate::config::Config>) -> (PathBuf, bool) {+ match config {+ Some(config) => (+ crate::security::credentials::state_dir_from_config(config),+ config.secrets.encrypt,+ ),+ None => (default_state_dir(), true),}}@@ -214,34 +148,6 @@ fn user_scoped_state_dir(root: &std::path::Path, active_user_id: Option<&str>) -)}-#[async_trait::async_trait]-impl EmbeddingModel for OpenHumanCloudEmbeddingModel {- fn name(&self) -> &str {- self.inner.name()- }-- fn model_id(&self) -> &str {- self.inner.model_id()- }-- fn dimensions(&self) -> usize {- self.inner.dimensions()- }-- fn signature(&self) -> String {- self.inner.signature()- }-- async fn embed(&self, texts: &[String]) -> tinyinference_embeddings::Result<Vec<Vec<f32>>> {- // Only a batch that will actually leave is guarded: an empty one- // answers locally, and a blank input is refused by the transport.- if !texts.is_empty() && texts.iter().all(|text| !text.trim().is_empty()) {- self.guard()?;- }- self.inner.embed(texts).await- }-}-#[cfg(test)]#[path = "cloud_adapter_tests.rs"]mod tests;diff --git a/crates/openhuman-core/src/inference/embedding_host/factory.rs b/crates/openhuman-core/src/inference/embedding_host/factory.rsindex 76f8bebd1b..8fe9d1b98a 100644--- a/crates/openhuman-core/src/inference/embedding_host/factory.rs+++ b/crates/openhuman-core/src/inference/embedding_host/factory.rs@@ -9,7 +9,7 @@ use tinyinference_embeddings::factory::{};use tinyinference_embeddings::EmbeddingModel;-use super::cloud::OpenHumanCloudEmbeddingModel;+use super::cloud::{credential_scope, UnavailableEmbeddingModel};use crate::inference::provider::factory::PROVIDER_OPENHUMAN;use crate::inference::registry::EmbeddingRequest;use crate::security::approval::ApprovalChatContext;@@ -33,17 +33,18 @@ fn managed_factory(config: &Config, chat: Option<ApprovalChatContext>) -> ManageArc::new(move |model, dimensions| {if let Some(registered) = crate::inference::registry::embedding(PROVIDER_OPENHUMAN) {log::debug!("[embeddings::factory] managed model served by a registered factory");+ let (state_dir, secrets_encrypt) = credential_scope(Some(&config));return registered(&EmbeddingRequest {config: Some(&config),model,dimensions,chat: chat.clone(),+ state_dir,+ secrets_encrypt,});}- Ok(Box::new(- OpenHumanCloudEmbeddingModel::from_config(&config, model, dimensions)- .routed_to(chat.clone()),- ))+ log::debug!("[embeddings::factory] no managed embedding provider registered");+ Ok(Box::new(UnavailableEmbeddingModel::new(model, dimensions)))})}@@ -69,16 +70,18 @@ pub fn create_embedding_provider_with_credentials(let managed: ManagedModelFactory = Arc::new(|model, dimensions| {if let Some(registered) = crate::inference::registry::embedding(PROVIDER_OPENHUMAN) {log::debug!("[embeddings::factory] managed model served by a registered factory");+ let (state_dir, secrets_encrypt) = credential_scope(None);return registered(&EmbeddingRequest {config: None,model,dimensions,chat: None,+ state_dir,+ secrets_encrypt,});}- Ok(Box::new(OpenHumanCloudEmbeddingModel::new_default_scope(- model, dimensions,- )))+ log::debug!("[embeddings::factory] no managed embedding provider registered");+ Ok(Box::new(UnavailableEmbeddingModel::new(model, dimensions)))});let model = create_configured_embedding_model(&settings(diff --git a/crates/openhuman-core/src/inference/embedding_host/mod.rs b/crates/openhuman-core/src/inference/embedding_host/mod.rsindex 0c58c171bc..4ea7458bbb 100644--- a/crates/openhuman-core/src/inference/embedding_host/mod.rs+++ b/crates/openhuman-core/src/inference/embedding_host/mod.rs@@ -20,7 +20,7 @@ mod rpc;mod schemas;pub use cloud::{- OpenHumanCloudEmbeddingModel, DEFAULT_CLOUD_EMBEDDING_DIMENSIONS, DEFAULT_CLOUD_EMBEDDING_MODEL,+ UnavailableEmbeddingModel, DEFAULT_CLOUD_EMBEDDING_DIMENSIONS, DEFAULT_CLOUD_EMBEDDING_MODEL,};pub use factory::{create_embedding_provider_for_chat, create_embedding_provider_with_config,diff --git a/crates/openhuman-core/src/web_chat/run_task.rs b/crates/openhuman-core/src/web_chat/run_task.rsindex bb11ba65c3..dc0ace8c76 100644--- a/crates/openhuman-core/src/web_chat/run_task.rs+++ b/crates/openhuman-core/src/web_chat/run_task.rs@@ -292,6 +292,8 @@ pub(crate) async fn run_chat_task(let speak_reply = matches!(metadata.speak_reply, Some(true));let trimmed_response = task_result.full_response.trim();if speak_reply && !trimmed_response.is_empty() {+ #[cfg(feature = "voice")]+ use crate::voice::TtsProvider as _;// Resolved through the voice registry by the hosted slug: the// provider is registered by the hosted-backend layer, so a core// with none registered logs the error and skips the spoken reply.