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(media): add generation provider abstraction
Steven Enamakel4b6721b845df
diff --git a/crates/openhuman-core/src/media/generation/provider.rs b/crates/openhuman-core/src/media/generation/provider.rsindex ae1fdcff1a..b5bb1f4df6 100644--- a/crates/openhuman-core/src/media/generation/provider.rs+++ b/crates/openhuman-core/src/media/generation/provider.rs@@ -252,3 +252,7 @@ impl VideoGenerator for GuardedVideo {self.inner.list_models().await}}++#[cfg(test)]+#[path = "provider_tests.rs"]+mod tests;diff --git a/crates/openhuman-core/src/media/generation/provider_tests.rs b/crates/openhuman-core/src/media/generation/provider_tests.rsnew file mode 100644index 0000000000..318a6f4fd8--- /dev/null+++ b/crates/openhuman-core/src/media/generation/provider_tests.rs@@ -0,0 +1,83 @@+use super::*;+use crate::core::events::DomainEvent;++fn guard(chat: Option<ApprovalChatContext>) -> Guard {+ Guard {+ config: Arc::new(Config::default()),+ chat,+ }+}++async fn disclosed_routing(+ rx: &mut tinybus::events::EventReceiver<DomainEvent>,+ service: &str,+) -> (Option<String>, Option<String>) {+ loop {+ match rx.recv().await {+ Some(DomainEvent::ExternalTransferPending {+ descriptor,+ thread_id,+ client_id,+ ..+ }) if descriptor.service == service => return (thread_id, client_id),+ Some(_) => continue,+ None => panic!("the bus closed before the disclosure arrived"),+ }+ }+}++/// A media request discloses its egress to the chat the call was built for, and+/// two guards built for different chats do not share a destination.+#[tokio::test]+async fn a_guard_discloses_to_the_chat_it_was_built_for() {+ crate::core::bus::init().await.expect("bus init");+ let mut rx = crate::core::bus::BUS.get().unwrap().receiver();++ let chat_a = ApprovalChatContext {+ thread_id: "thread-media-a".into(),+ client_id: "client-media-a".into(),+ request_id: None,+ };+ let chat_b = ApprovalChatContext {+ thread_id: "thread-media-b".into(),+ client_id: "client-media-b".into(),+ request_id: None,+ };+ let (a, b, none) = (guard(Some(chat_a)), guard(Some(chat_b)), guard(None));+ a.admit("videos/probe-a").unwrap();+ tokio::task::yield_now().await;+ b.admit("videos/probe-b").unwrap();+ none.admit("videos/probe-none").unwrap();++ let service = |route: &str| format!("{OPENROUTER_PROXY_PATH}/{route}");+ assert_eq!(+ disclosed_routing(&mut rx, &service("videos/probe-a")).await,+ (Some("thread-media-a".into()), Some("client-media-a".into()))+ );+ assert_eq!(+ disclosed_routing(&mut rx, &service("videos/probe-b")).await,+ (Some("thread-media-b".into()), Some("client-media-b".into()))+ );+ assert_eq!(+ disclosed_routing(&mut rx, &service("videos/probe-none")).await,+ (None, None)+ );+}++#[test]+fn generators_without_a_router_are_returned_as_they_are() {+ use tinyagents_harness::tinyinference_image::MockImageGenerator;+ use tinyagents_harness::tinyinference_video::{MockVideoGenerator, MockVideoScript};+ let generators = MediaGenerators::new(+ Arc::new(MockImageGenerator::new()),+ Arc::new(MockVideoGenerator::new(MockVideoScript::delivers())),+ );+ let routed = generators.routed(Some(&ApprovalChatContext {+ thread_id: "t".into(),+ client_id: "c".into(),+ request_id: None,+ }));+ assert!(Arc::ptr_eq(&generators.image, &routed.image));+ assert!(Arc::ptr_eq(&generators.video, &routed.video));+}+