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
feat(embedding): add cloud embedding adapter
Steven Enamakel412670bd4c81
diff --git a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rsindex 03ef1697cf..80c54fc87d 100644--- a/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs+++ b/crates/openhuman-core/src/inference/embedding_host/cloud_adapter.rs@@ -4,18 +4,29 @@ use std::path::PathBuf;use std::sync::Arc;use tinyinference_embeddings::{- BearerResolver, CloudEmbeddingModel, EmbeddingEgressGuard, EmbeddingModel,- DEFAULT_CLOUD_DIMENSIONS, DEFAULT_CLOUD_MODEL,+ BearerResolver, CloudEmbeddingModel, 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 around the crate-owned cloud transport.+/// 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: CloudEmbeddingModel,+ inner: Arc<CloudEmbeddingModel>,+ model: String,+ chat: Option<ApprovalChatContext>,}impl OpenHumanCloudEmbeddingModel {@@ -73,19 +84,41 @@ impl OpenHumanCloudEmbeddingModel {)})});- let guard: EmbeddingEgressGuard = Arc::new(|model, _input_count| {- let egress = crate::security::egress::EgressDescriptor::embedding("cloud", model);- crate::security::egress::enforce_egress(&egress)- .map_err(|error| tinyinference_embeddings::Error::Embedding(error.to_string()))?;- crate::security::egress::emit_external_transfer(None, egress);- Ok(())- });+ let model = model.into();+ Self {+ inner: Arc::new(CloudEmbeddingModel::new(+ base_url,+ model.clone(),+ dimensions,+ bearer,+ )),+ model,+ chat: None,+ }+ }++ /// 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: CloudEmbeddingModel::new(base_url, model, dimensions, bearer)- .with_egress_guard(guard),+ inner: Arc::clone(&self.inner),+ model: self.model.clone(),+ chat,}}+ /// 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(())+ }+pub fn from_config(config: &crate::config::Config, model: &str, dimensions: usize) -> Self {Self::new(config.api_url.clone(),@@ -200,6 +233,11 @@ impl EmbeddingModel for OpenHumanCloudEmbeddingModel {}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}}diff --git a/crates/openhuman-core/src/inference/embedding_host/factory.rs b/crates/openhuman-core/src/inference/embedding_host/factory.rsindex 37ada726e9..dfa7dfd7a1 100644--- a/crates/openhuman-core/src/inference/embedding_host/factory.rs+++ b/crates/openhuman-core/src/inference/embedding_host/factory.rs@@ -10,6 +10,7 @@ use tinyinference_embeddings::factory::{use tinyinference_embeddings::EmbeddingModel;use super::cloud::OpenHumanCloudEmbeddingModel;+use crate::security::approval::ApprovalChatContext;fn settings(provider: &str,@@ -25,12 +26,13 @@ fn settings(}}-fn managed_factory(config: &Config) -> ManagedModelFactory {+fn managed_factory(config: &Config, chat: Option<ApprovalChatContext>) -> ManagedModelFactory {let config = config.clone();Arc::new(move |model, dimensions| {- Ok(Box::new(OpenHumanCloudEmbeddingModel::from_config(- &config, model, dimensions,- )))+ Ok(Box::new(+ OpenHumanCloudEmbeddingModel::from_config(&config, model, dimensions)+ .routed_to(chat.clone()),+ ))})}